Copy link to clipboard
Copied
Hey all.
I'm preparing a new form for my office using Adobe Acrobat DC, and I'm trying to get the date to auto-populate in a form field. Following some instructions online, I set the field to be read-only, so users can't mess with it, and set it to calculate with the following custom calculation script:
-------------------------------
var today = new Date();
event.value = util.printd("m/d/yy", today);
------------------------------
This does, indeed, pull up the current date, but not dynamically: if I enter the script today, 11/25/19, it pulls that up, but if I open the document tomorrow, it'll still say 11/25/19, unless I re-enter the script, at which point it updates.
Thanks, in advance, for your help.
Copy link to clipboard
Copied
Use the script at document open.
Copy link to clipboard
Copied
Are you opening the form in Acrobat or Reader?
Unless there is something else happening on the form, there is nothing that should be stopping the calculation.
The first thing to do is to check the Console window for a reported error.
The next thing to do is to add a console.println statement to your code so you can see what's going on.
Here's a video that explains how to do it:
https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro
Copy link to clipboard
Copied
And yes, the correct way to do this is to set the date in a document script.
Copy link to clipboard
Copied
The calculation event doesn't get triggered when you open the file, so you should move your code to a doc-level script and change the last line to:
this.getField("Today").value = util.printd("m/d/yy", today);