Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Dynamic alter colour cell with JavaScript

Avatar

Level 1

Hello Guys,

I'm facing the current problem:

I want change a colour cell depends on the value of the cell variable. I'm using the following JavaScript code on the initialize event of this cell

data.First.MainTable.Table1.Row1.Cell6::initialize - (JavaScript, client)

var numrows = xfa.resolveNodes("data.First.MainTable.Table1.Row1[*]").length;

for (var i = 0; i < numrows; i++)

{

    var LV_DATA = xfa.resolveNode("data.First.MainTable.Table1.Row1[" + i + "].Cell6");

  

    switch(LV_DATA){

       case LV_DATA <= "2":

            this.border.fill.color.value = "0, 153, 0";

            break;

       case LV_DATA >= "3" && LV_DATA <= "6":

            this.border.fill.color.value = "255, 255, 0";

            break;

       case LV_DATA> "6":

            this.border.fill.color.value = "255, 0, 0";

            break;

       default:

            this.border.fill.color.value = "255, 255, 255";

    }

}

Print1.PNG

My output values is:

Print2.PNG

With this output on column RISK Level I should get the first two cells red and the last one yellow.

Can you help me?

1 Reply

Avatar

Level 3

Hi Diogofbp,

welcome to Adobe.

Please use below code there is some errors in your code, and use the layoutready.

data.First.MainTable.Table1.Row1.Cell6::layoutReady - (JavaScript, client)

var numrows = data.First.MainTable.Table1.Row1.instanceManager.count;

for (var i = 0; i < numrows; i++)

{

    var LV_DATA = xfa.resolveNode("data.First.MainTable.Table1.Row1["  +  i  +  "]").Cell6.rawValue;

    switch(LV_DATA){

      case LV_DATA <= "2":

            this.border.fill.color.value = "0, 153, 0";

            break;

      case LV_DATA >= "3" && LV_DATA <= "6":

            this.border.fill.color.value = "255, 255, 0";

            break;

      case LV_DATA> "6":

            this.border.fill.color.value = "255, 0, 0";

            break;

      default:

            this.border.fill.color.value = "255, 255, 255";

    }

}