5 Replies Latest reply on Jun 4, 2017 2:34 PM by mattt38353613

    Auto populate

    mattt38353613

      I need some help with java I need to be able to auto populate from my today field and put into another field. I need to script it so that it takes the number from the month position and auto populates a text in another. 06/4/17  to text = May.

        • 1. Re: Auto populate
          try67 MVP & Adobe Community Professional

          If the field is just showing the current date there's no reason to copy the value from it to another field. Just use this calculation script in the second field:

          event.value = util.printd("mmmm", new Date());

          • 2. Re: Auto populate
            gkaiseril MVP & Adobe Community Professional

            First Java does not work within an PDF form. The language used by PDF forms for scripting is JavaScript. JavaScript is not a compiled language as Java is.

             

            The code you will need has to be custom written and as such one needs very specific information. To access a given field's value one needs the exact field name. For dates and time the format use is very important. For example some areas of the world list the month first and then the date while other areas list the day first and then the month. I have even seen manual record that list dates as year, month, and then day.

             

            One can split the date string into three parts and then use the value for the month to look the abbreviated month letters in an array. Or one could convert the date character string to the JavaScript date object and then use Acrobat's util.printd method to get the short month characters.

             

            Since you are already using a script to populate today's date, why not add some additional code to populate month field.

             

            I am not sure how one gets "May" from a date string value of "06/4/17". I would read that string as June 4, 2017 or April 6, 2017. But I could even be wrong about the year since it could be 1917 and not 2017.

             

            So if I have a form with a field "Today", read only and no specified format, and I wanted to populate it with the system date formatted as "mm/dd/yyyy" when the form was opened I would create a document level script like:

             

            var Now = new Date(): // get the current system date and time;

            this.getField("Today").value = util.printd("mm/dd/yyyy", Now); // populate field Today with formatted system date;

             

            Since I have the current system date in the variable "Now", I should be able to get the 3 character month out of it and put it into a field named "Month" with the addition of a new line of code:

             

            this.getField("Month").value = util.printd("mmm", Now); // put the 3 character month into the Month field;

            • 3. Re: Auto populate
              mattt38353613 Level 1

              I need it to to be in text in the new field not the date format!

              01/../17 = january

              02/../17 = february

              08/../17= august and so on 

              • 4. Re: Auto populate
                try67 MVP & Adobe Community Professional

                I understood. The script I provided does that...

                • 5. Re: Auto populate
                  mattt38353613 Level 1

                  Thank you i knew it had to be something simple it worked