sc_field_style macro does not accept variable

I have a problem that the sc_field_style macro does not accept variable:

I use this in the OnRecord event on Grid app:

This works, but set all records to the specified colour, as expected:

sc_field_style({task_status}, '#ff0a0a' );

This does not work:

With single quotes:

$get_col = "SELECT colour_code from tbl_task_status where ID = {task_status}";
sc_lookup(rs_col, $get_col);
$bg_col= "'" .{rs_col[0][0]}."'"; // add single quotes
echo $bg_col;   //this returns the correct colour code
sc_field_style({task_status},$bg_col);

Without single quotes:

$get_col = "SELECT colour_code from tbl_task_status where ID = {task_status}";
sc_lookup(rs_col, $get_col);
$bg_col= {rs_col[0][0]}; // add single quotes
echo $bg_col;   //this returns the correct colour code
sc_field_style({task_status},$bg_col);

any idea how I could change the bg color on individual rows within the grid, based on the value of the field?

Hello,

Issue reported to our bugs team.

regards,
Bernhard Bernsmann

Solution

[QUOTE=symanix;14576]I have a problem that the sc_field_style macro does not accept variable:

I use this in the OnRecord event on Grid app:

This works, but set all records to the specified colour, as expected:

sc_field_style({task_status}, '#ff0a0a' );

This does not work:

With single quotes:

$get_col = "SELECT colour_code from tbl_task_status where ID = {task_status}";
sc_lookup(rs_col, $get_col);
$bg_col= "'" .{rs_col[0][0]}."'"; // add single quotes
echo $bg_col;   //this returns the correct colour code
sc_field_style({task_status},$bg_col);

Without single quotes:

$get_col = "SELECT colour_code from tbl_task_status where ID = {task_status}";
sc_lookup(rs_col, $get_col);
$bg_col= {rs_col[0][0]}; // add single quotes
echo $bg_col;   //this returns the correct colour code
sc_field_style({task_status},$bg_col);

any idea how I could change the bg color on individual rows within the grid, based on the value of the field?[/QUOTE]

Same problem, but try this, works for me:

$get_col = "SELECT colour_code from tbl_task_status where ID = {task_status}";
sc_lookup(rs_col, $get_col);
[bg_col]= {rs_col[0][0]}; // add single quotes
echo [bg_col];   //this returns the correct colour code
sc_field_style({task_status},[bg_col]);

Use Global varible. :stuck_out_tongue:

I am still seeing this same bug in SC version 8.00.0045.

Specifically, the macro sc_field_style will not accept the second parameter (it is the background color) as a {field} or $local variable. It will accept it as just putting in a quoted hex code like ‘#a12a12’ OR even as a [global] value.

So angelIrad’s work around still works, but this should be fixed so that a field value or local variable works too.

Just curiousity.
var_dump of var results to ‘#ff0a0a’ or ‘ff0a0a’?

In V9, this doesn’t work, even with a global variable.

try this without global val
onRecord:
$color = {color}; //#6BF903
sc_field_style({myfield},’’);
$this->NM_field_style[‘myfield’] = ‘background-color:’.$this->color.’;’;
in v9 => 9.04.0015

Bug still present also on V9.7.003
None of the above solutions work for me.
Is there anybody who knows a workaround?
Thanks

it is also frustrated for me

in one grid it works

// Farbeinstellung
[vcol]= {Einr_K_Farbe};
sc_field_style({Einr_K_Name},[vcol]);

in an other grid it doesn’t works

sc_lookup(rs, $check_sql);

if (isset({rs[0][0]}))
{
$v_Einr_Name = {rs[0][4]};
[v_Einr_Farbe] = {rs[0][5]};
}
else
{
$v_Einr_Name = ‘’;
[v_Einr_Farbe] =’#FFFF00’;
}
{txt_Einrichtung} = $v_Einr_Name;

echo [v_Einr_Farbe];

sc_field_style({txt_Einrichtung},[v_Einr_Farbe]);

echo shows me the correct color value

it was an uppercase problem

I changed the variable name from [v_Einr_Farbe] to [v_einr_farbe]

sc_field_style({txt_Einrichtung},[v_einr_farbe]);

it works !!

Unfortunately in nested grids it still doesn’t work.
@LP16 I tried to copy 1:1 your example but there is no way :frowning:
Can’t understand why for so many years such an apparently simple issue was never fixed or improved

UPDATE: I found the solution for my specific problem. In nested grids, there is a parameter in the linked grid “Visualization” that defines which embed application items will inherit the visual formatting of the main application. Switch off this parameter and the background color driven by a global variable is shown!