Expand my Community achievements bar.

Calculation across multiple pages?

Avatar

Level 1

I have a Total field that is supposed to count down all the fields in a single column in a table that spreads 2 pages (b_CASH_Row_1 to about 20 are on the first page, and the rest on the second page).

This is what I have typed in:

"this.rawValue = b_CASH_Row_1.rawValue + b_CASH_Row_2.rawValue + b_CASH_Row_3.rawValue + b_CASH_Row_4.rawValue + b_CASH_Row_5.rawValue + b_CASH_Row_6.rawValue + b_CASH_Row_7.rawValue + b_CASH_Row_8.rawValue + b_CASH_Row_9.rawValue + b_CASH_Row_10.rawValue + b_CASH_Row_11.rawValue + b_CASH_Row_12.rawValue + b_CASH_Row_13.rawValue + b_CASH_Row_14.rawValue + b_CASH_Row_15.rawValue + b_CASH_Row_16.rawValue + b_CASH_Row_17.rawValue + b_CASH_Row_18.rawValue + b_CASH_Row_19.rawValue + b_CASH_Row_20.rawValue + b_CASH_Row_21.rawValue + b_CASH_Row_22.rawValue + b_CASH_Row_23.rawValue + b_CASH_Row_25.rawValue + b_CASH_Row_26.rawValue + b_CASH_Row_27.rawValue + b_CASH_Row_28.rawValue + b_CASH_Row_29.rawValue + b_CASH_Row_30.rawValue + b_CASH_Row_31.rawValue + b_CASH_Row_32.rawValue + b_CASH_Row_33.rawValue + b_CASH_Row_34.rawValue;"

Now, when I use the same type of script for a table that spans one page, everything works fine, but across 2 pages, it does not seem to work. Is there a code I am suppose to imput in to make it calculate fields that are in another page?

Thanks in advance!

5 Replies

Avatar

Level 10

It should work if it's in the same subform. If it's in a different subform you'll need to add the path.

You should also be able to shorten your code considerably if it's a bunch of repeating table rows (or a bunch of repeating subforms).

Something along the lines of (using formcalc) this.rawValue = sum(b_CASH_Row_[*].rawValue)

Syntax may not be quite right but should give you the general idea, I'm going off the top of my head.

If you want javascript, look in the help under "calculating sums".

Avatar

Level 1

If I were to specify the subform, how would I do so? Form2[0].b_CASH_Row_1 for example?

Avatar

Level 10

While in the script editor hold down the ctrl key and mouse over the field you want to add - the mouse cursor should change to a "V" when you are over a valid object - and then left click on the field and the reference will get added to the script editor (ctrl gives the relative path and ctrl-shift gives the full path).

You have to make sure you are clicked in the script editor first though or nothing will happen.

Avatar

Level 1

We're getting closer!

I've included the fields from the first page into my calculation that's on the second page and it seems to take notice of them in my script (as when I test it, the calculated field already starts at 0.00), BUT whenever I enter an amount in the fields calculated in page 1, they do not add up to fields from field 2.

Here is my script:

this.rawValue = xfa.resolveNode("#subform[33].Form2.b_CASH_Row_1.rawValue") + xfa.resolveNode("#subform[33].Form2.b_CASH_Row_2.rawValue") + b_CASH_Row_31.rawValue

For example:

1 + 2 + 3 would equal just 3, because 1 and 2 don't seem to be counted in my script. Am I writting something wrong?

Thanks again!

Avatar

Level 7

The script you posted mixes relative field references with absolute references. Jono's got you on the right track, I would suggest referencing all your fields with absolute references just to eliminate any mistakes. The fact that you're getting a 0.00 to show up should mean that you're nearly there.