How to change color based on value

Hi.
I have a table with 30 fields. I want to change the color based on the value. I don’t want to change one by one, but to write a function, and my question is … How do I write this function?

In grid, load record…

if ({Pla.Finalizado} == 1) {
	sc_field_style({Pla.DESCRIPCION}, '', '', '#00FF00' , '', '');
} else {
	sc_field_style({Pla.DESCRIPCION}, '', '', '#99FFFF' , '', '');
}

@asantarelli
Thank you for your advice, but This what I already did.
but I have 30 fields, I do not want to write for each field.
I would like to use something like
function(fieldname)
if (fieldname.value>20)
{}
else {}

and call this function with the filed name.

I try to enclose the field name in “”, and work.
Then, you can write a function…

function ChangeColor($myField, $myValue)
if ($myValue == 1) {
sc_field_style($myField, ‘’, ‘’, ‘#00FF00’ , ‘’, ‘’);
} else {
sc_field_style($myField, ‘’, ‘’, ‘#99FFFF’ , ‘’, ‘’);
}

try this…

@asantarelli , and how to to pass the field name and value?

In OnRecord
ChangeColor("{Campo}",{Campo});

The first parameter, string, is the name of field
the second parameter, the actual value…

try…

@asantarelli
I tried this
event ->onRecord
FCol("{perCp1}",{perCp1});
where perCp1 is my field and it desn’t change the color of the text

I put this function to the Programming->PHP Methods->New method
Function fCol($fName,$fValue)
$mYellow="#FFCC00";
$mRed="#CC0000";
$mGreen="#66CC00";

if ( $fValue<20)
{
sc_field_style($fName ,’’ ,’’ , $mRed,’’,’’ );
}
elseif ($fValue>=20 and $fValue<=70)
{
sc_field_style($fName ,’’ ,’’ ,$mYellow ,’’ ,’’ );
}

else
{
sc_field_style($fName ,’’ ,’’ ,$mGreen ,’’ ,’’);
};

Sorry…
sc_field_style can’t be used from function…
I try to solve only the string of color, but sc_field_style not transform the result variable in a valid string color…
This code not work.
Sorry…

Thank you @asantarelli