1 Reply Latest reply on Feb 10, 2016 9:44 AM by gkaiseril

    Calculate grand total across multiple spawned pages.

    afsnyder

      Hello all. I have a form with a single page template. Users can spawn new pages as needed. Each page has a Page Total field and a Grand Total field.

      I would like the GT field on each page to collect and add up the values of all of the PT fields in the document. The trouble I'm having is that I can't seem to get the GT fields to grab page totals from other pages. Each GT field only displays the total of the page it's on. This is the calculation script I'm using:

      var prefix = "";

      var nameParts = event.target.name.split(".");

      if (nameParts.length > 2) {

          prefix = nameParts[0] + "." + nameParts[1] + ".";

      }

       

      var grandTotal;

       

      for (i = 0; i < this.numFields; i++)

          {

              var fname = this.getNthFieldName(i);

       

              if (fname == prefix + "pgtotal")

                  {

       

                      grandTotal += this.getField(this.getNthFieldName(i)).value;

       

                  }

       

          }

       

      event.value = grandTotal;

       

      What am I missing? Is there an easier way to go about calculating a grand total for the document to display on every page?

        • 1. Re: Calculate grand total across multiple spawned pages.
          gkaiseril MVP & Adobe Community Professional

          It looks like your script is using the first 2 elements of the grand total field and not updating for the various spawned pages.

           

          You do understand that a spawned page has a page reference prefix element and a template name prefix. The template name prefix is constant for any spawned page using that template. The page reference is changed for each spawned page. The first element for the hierarchical field name created by the renaming the fields for a spawned page is "p#" where the # is the zero based number for the spawned page.

           

          You need to change to account for the change in the "P#" element for the fields to be totaled.

           

          Have you tried to add some debugging statements to see the names of the fields you are adding? How does that list compare to the actual fields to be totaled?