How to do a partial sum of table rows in LiveCycle - Javascript

Avatar

Avatar
Level 1
rfs87731640
Level 1

Likes

0 likes

Total Posts

1 post

Correct reply

0 solutions
View profile

Avatar
Level 1
rfs87731640
Level 1

Likes

0 likes

Total Posts

1 post

Correct reply

0 solutions
View profile
rfs87731640
Level 1

15-04-2016

I have 4 rows (and 3 columns) in a table. The last row is the total. I need to sum only the first two rows, excluding the last one. The problem is they are all calculated values from different tables, how do I do it? I am new to Adobe LiveCycle and Javascript.

This is what I currently have:

var times = xfa.resolveNodes("Row2[*].Time"); this.rawValue = Calculate.SumRawValues(times);

I am trying something like this:

var times = xfa.resolveNodes("Row2[*].Time"); var timesFlushing = xfa.resolveNode("Row2[2].Time"); this.rawValue = Calculate.SumRawValues(times) - timesFlushing.value;

or something like this:

var times = xfa.resolveNodes("Row2[*].Time"); this.rawValue = Calculate.SumRawValues(times) - xfa.resolveNode("Row2[2].Time");

or even this:

this.rawValue = Row2.Time + xfa.resolveNode("Row2[1].Time")

Clearly I am new to this and none of these work. Help please??? Comments?

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-05-2016

There is a difference between the methods resolveNode() and resolveNodes(), which is decribed here: resolveNode vs. resolveNodes

For you needs, the following script should to the trick.

var times = xfa.resolveNodes("Row2[*].Time"),

    sum = 0;

for (var i = 0, j = times.length; i < j; i += 1) {

    if (i !== (j - 1) ) {

          sum += times.item(i).rawValue;

    }

}

this.rawValue = sum;

Note: This script will only work, if every row on you table is named "Row2".