Skip to main content
Participant
November 25, 2019
Question

Auto-populate form with date isn't working; stuck on last time script entered.

  • November 25, 2019
  • 3 replies
  • 581 views

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.

This topic has been closed for replies.

3 replies

try67
Community Expert
Community Expert
November 25, 2019

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

Thom Parker
Community Expert
Community Expert
November 25, 2019

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

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
Community Expert
November 25, 2019

And yes, the correct way to do this is to set the date in a document script. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
November 25, 2019

Use the script at document open.