Expand my Community achievements bar.

Script only applying to first occurrence

Avatar

Level 1

Hi,

I am attempting to dynamically change some colors on my form based on a condition with the following code:

data::ready:layout - (JavaScript, server)

if (xfa.resolveNode("data.#pageSet.DocumentHeader.TYPE").rawValue == "G2"){

     xfa.resolveNode("data.BODY.ITEM_DETAIL.HEADER_DETAIL.Total.border.fill.color").value = "60, 60, 160";

     xfa.resolveNode("data.#pageSet.DocumentHeader.DOC_TYPE").fontColor= "60,60,160"

     }

However this only applies to the first occurrence of 'Document Header' and 'Body'. What is the best way to change all occurrences of 'DOC_TYPE' and 'Total'?

Many thanks in advance!

1839352_pastedImage_3.png

1 Reply

Avatar

Level 10

First, don't use the name "data" for your root node, since "data" is already the name of the dataset the form data is stored in. Using the same name with other form objects can cause strange side effects. Rename it to "form" or someting else.

Ok, you need to reference all instances of the master page "DocumentHeader" and manipulate everyone of them separately.

The best way is to use a for loop like this:

var cType = form.#pageSet.DocumentHeader.TYPE").rawValue,

oHeaders = form.#pageSet.resolveNodes("DocumentHeader[*]"),

i;

for (i = 0; i < oHeaders.length; i += 1) {

    oHeaders.item(i).DOC_TYPE.fontColor = cType === "G2" ? "60,60,160" : "0,0,0";

}