22 Replies Latest reply on Jun 16, 2011 6:39 AM by dhoult

    Spawning problems in Acrobat

    csb102155 Level 1

      Hi, I'm having a problem in Adobe Acrobat with Spawning.

       

      I have the second page of a 2 page form set as a template.  However, when I use the button to 'add another page' the data in the fields of the first page gets copied over to the fields in the second page even though the template did rename the fields of the second page.  What am I doing wrong?

       

      This is the script that I have for a button event that 'adds another page'

       

      var a = this.getTemplate("biweekly")
      a.spawn ({
      nPage:this.numPages,
      bRename:true,
      bOverlay:false
      })
      this.pageNum = this.numPages-1;

       

      Thanks for any assistance with this.

      Connie

        • 1. Re: Spawning problems in Acrobat
          George_Johnson MVP & Adobe Community Professional

          If the fields already have values when you spawn the template, they will be copied. You could clear them afterwards if you want. If that's not the source of the problem, have you checked to see what the field names of fields on the new page are?

          • 2. Re: Spawning problems in Acrobat
            csb102155 Level 1

            Well, the fields are filled in by the user, and then when the user gets to the bottom of the page, needs to add another page and add more data to the fields.  How can we clear the second or subsequent pages without wiping out all the data from the first page?

             

            Thanks for your assistance.

             

            Connie

            • 3. Re: Spawning problems in Acrobat
              try67 MVP & Adobe Community Professional

              The fields are renamed according to a set pattern that includes the page

              number, template name and original field name.

              Using this information you can find them and clear them. Another option is

              to search for all fields whose page property equals that of the new page.

              • 4. Re: Spawning problems in Acrobat
                George_Johnson MVP & Adobe Community Professional

                Since the fields are named differently than the fields on the first page, and since the field names follow a naming convention, you can clear them individually. For example:

                 

                // Get the field name prefix that Acrobat automatically adds to the new fields
                var f_prefix = "P" + (this.numPages - 1) + ".biweekly";
                
                // Reset the newly created fields
                this.resetForm([f_prefix]);
                
                // Go to the new page
                this.pageNum = this.numPages-1;
                
                
                
                • 5. Re: Spawning problems in Acrobat
                  csb102155 Level 1

                  Ok, I'm beginning to see what I think the problem is.  I have javascript calculations in the fields.  The javascript fields are the ones that get copied over to the next page.  What this is, is an overtime sheet.  It totals overtime is 3 different categories, and then there is a grand total.  So, in essence, the fields get the name change, but the javascript doesn't change inside the fields.  Is there a way around that?  (sigh, my head is spinning)

                  • 6. Re: Spawning problems in Acrobat
                    George_Johnson MVP & Adobe Community Professional

                    You'd have to change the JavaScript to work properly regardless of how many pages are present. If you show your current code and explain exactly how you want it to work, we might be able to make suggestions.

                     

                    In addition, you can force a recalculation after the page is spawned using the calculateNow method: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.447.html

                    • 7. Re: Spawning problems in Acrobat
                      gkaiseril MVP & Adobe Community Professional

                      If the form field names are the same as the form field names in your template, then when the template is spawned the contents of the same named fields will be copied and then the fields will be renamed.

                       

                      If you have script, then your scripts will need to be able to adjust for the various pages they are on.

                       

                      The renaming to the template fields follows following structure:

                       

                      P#.templateName.fieldName

                       

                      "P" is a fixed value

                      "#" is the zero based page number

                      "templateName" is the name of the template that was used to spawn the page

                      "fieldName" is the field name on that page

                       

                      I have found that crate the visible pages with the field names prefixed with "P0,templateName." and the template only having field names. makes the coding easier and the values from the visible first page is not copied over.

                       

                      You will have to adjust the scripts the calculations on the page to dynamically picking up the zero based page number of the form page or use document level functions for the calculations and those functions take a parameter for the zero based page number of the page on which the field being processed is located on.

                       

                      A Lesson in Templates for Adobe Acrobat

                      • 8. Re: Spawning problems in Acrobat
                        csb102155 Level 1

                        The scripts that I have is below.  Hopefully I can be clear on this.  I'm giving one row example.

                         

                        I have a row of fields,  It starts with the entry hours total, balanace forward, and then a row of W (Worked) fields called W1.1 to W1.14

                         

                        I have a field next to W1.14 named:  htp1.0, the javascript is:

                        var f = this.getField("W1");
                           var a = f.getArray();
                            var sum = 0;
                            for (i =0; i < a.length; i++)
                            sum += +a[i].value;
                        if (sum !=0)
                            event.value = sum;
                        else
                        event.value = "";

                         

                        I have a field next to the one above named:  htd1.0,  the javascript is:

                        var hours = this.getField("htp1.0")
                        var balance = this.getField("balance1.0")
                        if (hours.value !=0)
                        event.value = hours.value + balance.value
                        else
                        event.value = ""

                         

                        I have a field name next to the above: TOH1.0 and the javascript is:

                        var htd1 = this.getField("htd1.0")
                        var htd2 = this.getField("htd2.0")
                        var htd3 = this.getField("htd3.0")
                        var entry = this.getField("entryhour.0")
                        if (htd1.value !=0)
                        event.value = htd1.value + htd2.value + htd3.value + entry.value
                        else
                        event.value = ""

                         

                        How can I set this up so that the javascript changes to calculate on the new page when the page is spawned?  If you're confuse, I can send the file if I have an email address to send to.  Thank you so much for your time and assistance with this.

                        • 9. Re: Spawning problems in Acrobat
                          George_Johnson MVP & Adobe Community Professional

                          Do you want the fields one each new page to calculate just based on other fields on the same page, or will fields on more than one page be involved in a calculation? Maybe it would be easier to send the file. If you can't post it somewhere, I'd be happy to take a look. My address is in my profile.

                          • 10. Re: Spawning problems in Acrobat
                            gkaiseril MVP & Adobe Community Professional

                            For the first script:

                             

                            // assume no field name prefix

                            var cFieldPrefix = "";

                            // compute the field name prefix for the fields on this page
                            // get the field name
                            var cFieldName = event.target.name;
                            // convert the full filed name to an array
                            var aFieldName = cFieldName.split(".");
                            // only build the prefix if we have enough name levels
                            if (aFieldName.length > 2) {
                               // element 0 of the field name array is P#
                               // element 1 of the field name is the template that created the page
                               // elements 2 on are the rest of the field name and not used as a prefix
                               cFieldPrefix = aFieldName[0] + "." + aFieldName[1] + ".";

                               } // end building the prefix string

                            // preform the computation
                            var f = this.getField(cFieldPrefix + "W1");
                               var a = f.getArray();
                                var sum = 0;
                                for (i =0; i < a.length; i++)
                                sum += +a[i].value;
                            if (sum !=0)
                                event.value = sum;
                            else

                               event.value = "";

                             

                            You just need to add the code to compute the

                             

                            It is even possible to add a document level script to return the field name prefix string, so one would only need to modify the 'this.getField()' statements.

                             

                            The document level function:

                             

                            function getFieldPrefix(cFieldName) {
                            // assume no field name prefix
                            var cFieldPrefix = "";
                            // compute the field name prefix for the fields on this page
                            // convert the full filed name to an array
                            var aFieldName = event.target.name.split(".");
                            // only build the prefix if we have enough name levels
                            if (aFieldName.length > 2) {
                               // element 0 of the field name array is P#
                               // element 1 of the field name is the template that created the page
                               // elements 2 on are the rest of the field name and not used as a prefix
                               cFieldPrefix = aFieldName[0] + "." + aFieldName[1] + ".";
                               } // end building the prefix string
                            return cFieldPrefix;
                            } // end getFieldPrefix

                             

                            The custom field calcualtion script:

                             

                            // preform the computation
                            var f = this.getField(getFieldPrefix() + "W1");
                               var a = f.getArray();
                                var sum = 0;
                                for (i =0; i < a.length; i++)
                                sum += +a[i].value;
                            if (sum !=0)
                                event.value = sum;
                            else

                               event.value = "";

                            1 person found this helpful
                            • 11. Re: Spawning problems in Acrobat
                              csb102155 Level 1

                              Hi George:

                               

                              I set the document Javascripts to the script you showed below, and then did a custom field javascript.  The javascripts for the most part, worked on the first page.  The custom field javascript does not always all all the fields together.

                               

                              When I spawned the second page, the custom field javascripts were the same as the first page even though the field names were changed and the hours entered in the fields on the first page copied over to the second page.

                               

                              Any suggestions?

                               

                              thanks

                              Connie

                              • 12. Re: Spawning problems in Acrobat
                                gkaiseril MVP & Adobe Community Professional

                                Can we have access to a copy of the form?

                                • 13. Re: Spawning problems in Acrobat
                                  csb102155 Level 1

                                  I can temporarily post it to our public website, or send it email.  Which ever is preferred.

                                   

                                  Connie

                                  • 14. Re: Spawning problems in Acrobat
                                    gkaiseril MVP & Adobe Community Professional

                                    It sounds like the first page of the form has the same field names as the template, or the first page is the template.

                                    • 15. Re: Spawning problems in Acrobat
                                      csb102155 Level 1

                                      The instructions are the first page, the second page is the actual form and is a template.  You can go here to this website to view the form.

                                       

                                      http://mdotwas1.mdot.state.mi.us/public/webforms/ and type in 1139A in the Form Search by Form Number.

                                       

                                      I'll keep it there for a few days and then I will have to remove it.  The form is not done -  I only have the group done for the first employee.

                                       

                                      Let me know if you can think of a better way to handle the calculations and the spawning.

                                       

                                      What I am looking for is for the scripts to calculate and then when the user gets to the bottom of the page, they can "add a page" to continue on without having the previous page's data on it.

                                       

                                      Thanks

                                      Connie

                                      • 16. Re: Spawning problems in Acrobat
                                        Bernd Alheit Adobe Community Professional & MVP

                                        Don't use the template as second page.

                                        • clear the form
                                        • add a page
                                        • make the template invisible
                                        • save the document
                                        • 17. Re: Spawning problems in Acrobat
                                          gkaiseril MVP & Adobe Community Professional

                                          You need to understand that all text fields with the same name will be set to the same value as all the other text fields with the same name whether the PDF page is a template or not. It is not a good idea to use an active form page and a template at the same time.

                                           

                                          When a template is spawned, a copy of the template page is added to the PDF with its field names. If the rename parameter of the spawn page is set to rename, only after the page is add, are the field names renamed. So if any of the form pages have any field with the same name as a field on a template, the spawned page and similar field will have the value of the form field on a form page that matches the name the template page, but with an updated name when you see it. This is the very reason you should not use a form page as a template at the same time. This behavior may be useful if one wants to carry some data across all spawned pages.

                                           

                                          If your form page is not the first page of the PDF, then you will need to adjust the 'P#." prefix value on the form page to match the zero based page number. You also do not want to spawn pages before an existing page as this could cause field name conflicts, as existing filed names are not updated as new pages are added by spawning.

                                           

                                          You also have the template for the form hidden.

                                          • 18. Re: Spawning problems in Acrobat
                                            csb102155 Level 1

                                            I'm still working on the spawning for this document, however, I've used the scripts below, and sometimes it doesn't always add up the totals correctly.

                                             

                                            For the Document Javascript, I took George's script from a previous message:

                                             

                                            function getWB4(cWB4) {
                                            // assume no field name prefix
                                            var cWB4 = "";
                                            // compute the field name prefix for the fields on this page
                                            // convert the full filed name to an array
                                            var aWB4 = event.target.name.split(".");
                                            // only build the prefix if we have enough name levels
                                            if (aWB4.length > 2) {
                                               // element 0 of the field name array is P#
                                               // element 1 of the field name is the template that created the page
                                               // elements 2 on are the rest of the field name and not used as a prefix
                                               cWB4 = aWB4[0] + "." + aWB4[1] + ".";
                                               } // end building the prefix string
                                            return cWB4;
                                            } // end getWB4

                                             

                                            The custom field calcualtion script:

                                             

                                            // preform the computation
                                            var f = this.getField(getWB4() + "WB4");
                                               var a = f.getArray();
                                                var sum = 0;
                                                for (i =0; i < a.length; i++)
                                                sum += +a[i].value;
                                            if (sum !=0)
                                                event.value = sum;
                                            else

                                               event.value = "";

                                             

                                            After I go in to look at the scripts and then go back out of that specific field, it then calculates it correctly.  I think this Javascript is messing with me.

                                            When I use this script above, It does work when spawning pages.  I just need to get the javascript to total correctly.  Any suggestions?

                                             

                                             

                                             

                                             

                                             

                                            • 19. Re: Spawning problems in Acrobat
                                              gkaiseril MVP & Adobe Community Professional

                                              Check the calculation order of your form fields.

                                               

                                              Also check to see that you do not have an unwanted "event.value = "";" line within your script.

                                               

                                              I prefer to default the value of the field then perform a calculation and update the field value is it is not zero or what ever criteria I use to update the field.

                                              • 20. Re: Spawning problems in Acrobat
                                                csb102155 Level 1

                                                Hi:

                                                 

                                                How does one go about adjusting the 'P#." prefix value on the form page to match the zero based page number?  I've never done this before.

                                                 

                                                Thanks

                                                Connie

                                                • 21. Re: Spawning problems in Acrobat
                                                  dhoult

                                                  GKaiseril wrote:

                                                   

                                                  ...You also do not want to spawn pages before an existing page as this could cause field name conflicts, as existing filed names are not updated as new pages are added by spawning...

                                                  I'm currently having this exact problem, but I really don't want to spawn all my pages at the end of the document.  Any ideas how to avoid this?