4 Replies Latest reply on May 28, 2009 7:16 PM by Jo_2005

    Adding Multiple Fields - Script

    Jo_2005 Level 1

      Hello,

       

      I have multiple fields added in a batch processing script which works fine except for the last field created in the script called "TodayDate2".

       

      This field does not get added to the document.

       

      Can someone please review and advise a possible solution with my script?

       

      // Create signature fields dynamically

      var numpages = this.numPages;
      for (var i=0; i < numpages; i++)


      var f = this.addField("Prepared Signature", "signature", 1,
      [320, 660, 450, 640]);

      var g = this.addField("Reviewed Signature", "signature", 1,
      [320, 630, 450, 610]);

      var h = this.addField("Approved Signature", "signature", 1,
      [320, 600, 450, 580]);

       

      // Creates text field for today's date

      var numpages = this.numPages;
      for (var i=0; i < numpages; i++)


      var f = this.addField("TodayDate1", "text", 1,
      [460, 660, 540, 640]);
      f.userName = "Today's Date"
      f.value = "Automatic Update";
      f.readonly = true;
      f.textSetFieldLabel("Today's date will be entered upon Signing");

       

      var j = this.addField("TodayDate2", "text", 1,
      [460, 600, 540, 640]);
      j.userName = "Today's Date"
      j.value = "Automatic Update";
      j.readonly = true;
      j.textSetFieldLabel("Today's date will be entered upon Signing");


        • 1. Re: Adding Multiple Fields - Script
          Bernd Alheit Adobe Community Professional & MVP

          Did you read the documentation (Acrobat JavaScript API Reference) ?

           

          Missing ';' at end of line f.userName = "Today's Date"

          Why did you add the fields only to the second page of the document?

          f.textSetFieldLabel("Today's date will be entered upon Signing");

          A function named textSetFieldLabel doesn't exists.

           

          Did you check your code in the JavaScript Debugger?

          • 2. Re: Adding Multiple Fields - Script
            Jo_2005 Level 1

            Hello Bernd,

             

            Thank you very much for your reply and valuable assistance.  I really appreciate the help you are giving me.

             

            I have inserted the missing ; semicolon at the end of line f.userName = "Today's Date".

            I have also removed the variable > f.textSetFieldLabel("Today's date will be entered upon Signing"); from the script.

             

            This script works perfectly and inserts three digital signature fields and three text fields on page 2 of the document.

             

            (Page 2 is the only page requiring these fields as it is the only page requiring digital signatures).

             

            What I now need to add to the script is a set action for the three digital signature fields.

             

            This set action will insert today's date into the text field when the digital signature field is signed.

             

            I have added this set action to the first digital signature field part of the script, but now the script will not work.

             

            The javascript debugger decoded that there was a missing bracket in the set action part of the script, but after checking I cannot see where the script is going wrong.

             

            The script is as follows and the set action is highlighted.

             

            Can you please advise where there is a problem in the script?

             

            /// Create signature field dynamically, create text field for today's date

            var numpages = this.numPages;
            for (var i=0; i < numpages; i++)


            var f = this.addField("Prepared Signature", "signature", 1,
            [320, 660, 450, 640]);

            f.setAction("OnFocus", "var f = this.getField('TodayDate1'); f.value = util.printd('d/mm/yyyy', new Date());");

            var g = this.addField("Reviewed Signature", "signature", 1,
            [320, 630, 450, 610]);

            var h = this.addField("Approved Signature", "signature", 1,
            [320, 600, 450, 580]);

            // Create Date field dynamically for employee signature field

            var numpages = this.numPages;
            for (var i=0; i < numpages; i++)

            var p = this.addField("TodayDate1", "text", 1,
            [460, 660, 540, 640]);

            p.userName = "Today's Date";
            p.value = "Automatic Update";
            p.readonly = true;


            var i = this.addField("TodayDate2", "text", 1,
            [460, 600, 540, 640]);

            i.userName = "Today's Date";
            i.value = "Automatic Update";
            i.readonly = true;

            var j = this.addField("TodayDate3", "text", 1,
            [460, 540, 540, 640]);

            j.userName = "Today's Date";
            j.value = "Automatic Update";
            j.readonly = true;

             

             

             

            • 3. Re: Adding Multiple Fields - Script
              Bernd Alheit Adobe Community Professional & MVP

              Why did you use a loop over all pages when you add the fields only to the second page?

               

              I can't get any error using the f.setAction code.

              • 4. Re: Adding Multiple Fields - Script
                Jo_2005 Level 1

                Hello Bernd,

                 

                I have removed the reference to loop over all pages and the script now works "excellent".

                 

                Thank you for your valuable assistance, your advise has been very helpful in completing this script.

                 

                I have included the completed script below as a reference:

                 

                /// Create signature field dynamically, create text field for today's date


                var f = this.addField("Prepared Signature", "signature", 1,
                [320, 660, 450, 640]);

                f.setAction("OnFocus", "var f = this.getField('TodayDate1'); f.value = util.printd('d/mm/yyyy', new Date());");

                var g = this.addField("Reviewed Signature", "signature", 1,
                [320, 630, 450, 610]);
                g.setAction("OnFocus", "var g = this.getField('TodayDate2'); g.value = util.printd('d/mm/yyyy', new Date());");

                var h = this.addField("Approved Signature", "signature", 1,
                [320, 600, 450, 580]);

                h.setAction("OnFocus", "var h = this.getField('TodayDate3'); h.value = util.printd('d/mm/yyyy', new Date());");

                 

                 

                // Create Date field dynamically for employee signature field


                var p = this.addField("TodayDate1", "text", 1,
                [460, 660, 540, 640]);

                p.userName = "Today's Date";
                p.value = "Automatic Update";
                p.readonly = true;
                p.textSize = 12;

                var i = this.addField("TodayDate2", "text", 1,
                [460, 630, 540, 610]);

                i.userName = "Today's Date";
                i.value = "Automatic Update";
                i.readonly = true;
                i.textSize = 12;

                var j = this.addField("TodayDate3", "text", 1,
                [460, 600, 540, 580]);

                j.userName = "Today's Date";
                j.value = "Automatic Update";
                j.readonly = true;
                j.textSize = 12;