6 Replies Latest reply on Jul 6, 2011 11:35 AM by DC Dowd

    Scripting Help

    Cypherlok

      I am trying to create sequential serial number fields of four fields in a form.  The problem is, I need the number to be in the format of 00001.

       

      Serial 1 = User Defined  - This field is required and needs to be in the format of "#####"

      Serial 2 = Serial 1+00001. - This field is automatic and read only.

      Serial 3 = Serial 1+00002. - This field is automatic and read only.

      Serial 4 = Serial 1+00003. - This field is automatic and read only.

       

      I have tried to look up how to do this but I'm not sure where to start.  If someone could throw me a sample code for Adobe Pro 9, I would appreciate it very much.  Thanks!

        • 1. Re: Scripting Help
          George_Johnson MVP & Adobe Community Professional

          So if the first one is "12345", should the second be "123450001" or "12346", or something else?

          • 2. Re: Scripting Help
            Cypherlok Level 1

            S# is for the actual number itself.  I have a read only field for the other part of the serial number.

             

            S1 should be 00001 - User defined

            S2 should be 00002 - Automatic

            S3 should be 00003 - Automatic

            S4 should be 00004 - Automatic

             

            Thanks for any help.

            • 3. Re: Scripting Help
              gkaiseril MVP & Adobe Community Professional

              Assuming your serial number fields are sequentially numbered with only numbers and leading zeros. The maximum field length if 5 characters, Fields are named S1 - S10, all fields are formatted to the 'None' format.

               

              The "Validation Script" for field S1 is:

               

              var cFieldPrefix = "S";
              var nNumberFields = 10;
              if(isNaN(event.value) ) {
              app.alert("Must enter a numeric value");
              event.rc = false;
              } else {
              var nCharLimit = this.getField(event.target.name).charLimit;
              event.value = util.printf("%,10" + nCharLimit + ".0f", event.value);
              for(i = 1; i < nNumberFields; i++ ) {

              this.getField(cFieldPrefix + (i + 1)).value =  util.printf("%,10" + nCharLimit + ".0f", (Number(event.value) + i));
              } // end for loop
              event.rc = true;
              } // end if then else

              • 4. Re: Scripting Help
                Cypherlok Level 1

                Thanks so much, this works flawlessly.  I'll probably break it 10 times before I learn anything but thanks for the great start!

                • 5. Re: Scripting Help
                  Cypherlok Level 1

                  How would I go about formatting the input to a five digit number?  The user can type 1 or 00001, either way would be fine but I would like to have the rest of the fields display 00002, 00003, etc. Thanks again for the help.

                  • 6. Re: Scripting Help
                    DC Dowd

                    you could try opening the field properties, selecting the "Format" tab, choosing "Special" from the drop-down (combobox, in Adobe), then selecting "Arbitrary Mask" on the list and inputting "99999" in the space provided. That should format the contents of the field to five digits of 0-9 value.

                     

                    Not 100% sure, as I'm relatively new to Acrobat myself.