These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Sum of numeric fields in repeated subforms

bzooz
Registered: Jan 28 2010
Posts: 4

Hi everyone,

Can someone tell me what I'm missing here.

I have a subform called "CourseDetails" that can be repeated with an addInstance button.

In the subform is a drop-down menu from which people can choose courses. Also in the subform is a numeric field )"Cost") that shows the cost of the courses. This is the script:
Cost.rawValue = Vals.myVals[xfa.event.change].Cost;

In another subform called "Footer" is a "Total" field with a calculate event. I would like the "Total" field to add up all the "Cost" fields. However, it's only showing the total from the first "Cost" field -- it doesn't add other repeated "Cost fields".

Here's the script for the "Total" field:

var oFields = xfa.resolveNodes("$form..CourseDetails[*].Cost");
var nNodesLength = oFields.length;
var nSum = 0;
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {
nSum += oFields.item(nNodeCount).rawValue;
}
Total.rawValue = nSum;

Thanks very much for any help you can provide.
David

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The script looks correct so you need to do some debug to figure out what's going on.

Firt, is anything reported in the Console Window?

Next you need to place console.println() statments in the code to answer some questions:
1. How many nodes are being returned from the "resolveNodes" call

console.println("length: " + oFields.length);

2. What are the values of the returned nodes.

console.println("value"+ nNodeCount + ": " + oFields.item(nNodeCount).rawValue);

This will give you a place to start. If the problem is with the number of node returned there may be an issue with the structure of the form or with how the SOM path is constructed. You can run the resolveNodes line from the console window to figure out the best SOM path.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

bzooz
Registered: Jan 28 2010
Posts: 4
Thanks very much Thom. Fortunately it wasn't that complicated. Was simply missing an execCalculate. Derrrr.
Thanks for replying.
Cheers,
David