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

Subforms SubTotals and Grand Totals

pat_c08
Registered: Sep 17 2007
Posts: 15

Hi, new form..new question..please help!

I have a dynamic pdf with add a page to add subforms as needed. I have a grand total field and and a subtotal field..I can't get the grand total field to work ex: subtotal for subform1 is 50; so grand total is 50; subtotal on subform2 is 40 so grand total should be 90 etc...

I found this script for repeating subforms but I can't get it to work..my grandtotal field is showing 0

form1.#subform[0].pagina1.gtotal::calculate: - (JavaScript, client) -

var fields = xfa.resolveNodes("subform[*].nfield3");
var nSum = 0;
for (var i=0; i <= fields.length-1; i++) {

nSum = nSum + fields.item(i).rawValue
}

gtotal.rawValue = nSum;

whatelse need to be done in order for this to work...

thanks all

sconforms
Expert
Registered: Jul 10 2007
Posts: 92
The script you found is headed in the right direction however this can be made much simpler by using a FormCalc script. FormCalc easily supports little spreadsheet-like expressions that calculate, amongst other things, sums.

Let's say you have a repeatable subform named "Row" which contains a field named "Price". You also have a subform following the "Row" subform which contains a field named "GrandTotal". You can get the "GrandTotal" field to show the summation of all the "Price" fields (in each instance of the "Row" subforms added) by specifying a Calculate script, on the "GrandTotal" field, that looks like this:

SUM(Row[*].Price)
This means, "calculate the sum of all 'Price' fields found in all instances of the 'Row' subform."

Now this assumes that you will always have one instance of the "Row" subform. If you could have zero instances, then the script would issue an error when there are zero instances because the scripting engine will not be able to find the "Row" object. In that case, you would first check to see how many instances of the "Row" subform currently exist and react accordingly:

if (_Row.count > 0) thenSUM(Row[*].Price)else0endif

Remember: These script snippets are in FormCalc so make sure you set that as your scripting language in the Calculate event of the "GrandTotal" field using the Script Editor palette.

Stefan Cameron obtained his bachelor's degree with Honors in Computer Science at the University of Ottawa and is a Computer Scientist working on Adobe's LiveCycle server products, in particular on LiveCycle Designer ES for the past 5 years.

pat_c08
Registered: Sep 17 2007
Posts: 15
Thank you..your information was very helpful...

and I figure out what was wrong with the JS ... I didn't reference the subform correctly and it I wouldn't have figure it out without your explanation of using FCalc..

These Forums are soooo valuable! Keep up the Excellent Work!

Again Thanks and Season's Greetings!