Style a grid field using a variable for the Hex color code

The following line, inserted in an onRecord event, will change the color of the background, based on the value of DAFF33

sc_field_style({colorName}, ‘#DAFF33’, ‘15px’, ‘#FF6666’, ‘Arial, sans-serif’, ‘bold’);

I would like to change the color row by row for the field “colorName”, by reading it in from a table.

I have tried :

$col = “#DAFF33”;

sc_field_style({colorName}, $col, ‘15px’, ‘#FF6666’, ‘Arial, sans-serif’, ‘bold’);

but it does not work

How can I use a variable to change the BG of that field, on a row by row basis.?

The photo attached is what it should look like

I too have battled with this one. For some strange reason you can not pass variable to the function

So here is what I found.
If I make the variable global it works
$cola=#DAFF33;
sc_set_global($cola);
sc_field_style({app_name}, [cola], ‘15px’, ‘#FF6666’, ‘Arial, sans-serif’, ‘bold’);

I had to change $col to $cola as this did also not work.
The last thing was to change the Global Variable in the Application to out

Not the best solution, but it works for now.

1 Like

TY Nico, that works for me!!

Strangely though, I also need to set the font color, and the same technique does not work.

You would think the same code would work for BG and font. Have you tried that?

Thanks again for the help

Just check the c on fontcolr … it seems like when doing the set_global your using a lower case.

Just had a strange experience with this.
I’ve used the global variable technique for some years and it has worked fine.
Just created a New application on v9.009 and it doesn’t work.

The code is simple and mirrors Nicos above…
sc_field_style({Colour}, “#f5989e”); / /This works OK but not what I want
$Coltext = {Colour}; //reads the colour of the field in hex
sc_set_global($Coltext);
{Notes} = [Coltext]; //did this to post hex value to separate field to check it was picking up the correct value (It does)
sc_field_style({Colour}, [Coltext]); // this doesn’t work.

It has me worried as I have dozens of working versions of this in my apps. I’m hoping that SC have not broken it otherwise I’ll not be able to maintain existing grids for fear of breaking the colour coding that all of the users are used to!

Any ideas???