4 Replies Latest reply on Feb 28, 2012 8:08 AM by MarkWalsh

    Calculations on spawned template pages

    MarkWalsh Level 4

      I haven't had to use templates much, and it was a long time ago when I did, but I am helping a coworker with a form that needs to calculate totals from a template page.

       

      The template has fields qty.1, qty.2, qty.3... etc., and I had originally created a field on the template page that was a calculation of the sum of qty. Of course it worked when testing on the template page, but the spawned pages show 0 since they are still calculating the values from the original template page.

       

      Is there a way for the spawned pages to automatically calculate the subtotal for the page, as well as creating a calculation which will calculate a grand total for all of the pages?

        • 1. Re: Calculations on spawned template pages
          gkaiseril MVP & Adobe Community Professional

          I assume you are renaming the fields on the spawned pages.

           

          You will notice that the form fields are prefixed with the the page number and the template that the new page was crated from. So you need to adjust your scripts to extract these prefix values and use then to adjust you scripts.

           

          I find that renaming your page 1 field to include the "P0.[templateName]." prefix makes all of the coding on each page consistent.

          • 2. Re: Calculations on spawned template pages
            MarkWalsh Level 4

            Thanks for the reply. The fields are renamed when the pages are spawned (rename parameter is true), but the calculated value on the spawned page does not reflect the renamed fields on the spawned page. I'll try your tip on renaming the fields on the template to match the spawned pages to see if that helps.

            • 3. Re: Calculations on spawned template pages
              gkaiseril MVP & Adobe Community Professional

              Do not change the names for the fields on the template.

               

              I create the template, then spawn the first page. Now I create the scripts for the first page and create variables for the "P#" and "template" name prefixes. After I get them debugged on page 1, I add the scripts to the template and spawn a second page and test the scripts.

              • 4. Re: Calculations on spawned template pages
                MarkWalsh Level 4

                Ok, I think I get what you are saying.

                 

                If I understand you, I need to create a custom calculation (instead of using the simple 'sum' of the desired field) which parses the page# and template name from the calculated field name (event.target.name) and use that to determine the fields to use for the calculation on that page.

                 

                Another question, I noticed that if the user deletes a spawned page, then a new page could be generated which uses the same name as an existing page (e.g. if page 3 of 4 is deleted, then the next page spawned will also use #4 and duplicate the values on both pages). Is there any way to avoid/correct this?