Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Auto populate

New Here ,
Jun 04, 2017 Jun 04, 2017

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.

TOPICS
Acrobat SDK and JavaScript
404
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2017 Jun 04, 2017

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());

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 04, 2017 Jun 04, 2017

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 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2017 Jun 04, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 04, 2017 Jun 04, 2017
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 04, 2017 Jun 04, 2017

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines