Script only applying to first occurrence

Avatar

Avatar
Validate 1
Level 1
matthewh7973307
Level 1

Like

1 like

Total Posts

2 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
matthewh7973307
Level 1

Like

1 like

Total Posts

2 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
matthewh7973307
Level 1

02-10-2019

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

Accepted Solutions (0)

Answers (1)

Answers (1)

Avatar

Avatar
Coach
MVP
radzmar
MVP

Likes

397 likes

Total Posts

2,687 posts

Correct reply

492 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile

Avatar
Coach
MVP
radzmar
MVP

Likes

397 likes

Total Posts

2,687 posts

Correct reply

492 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile
radzmar
MVP

02-10-2019

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";

}