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

New Here ,
Nov 25, 2019 Nov 25, 2019

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.

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

74

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Nov 25, 2019 Nov 25, 2019

Copy link to clipboard

Copied

Use the script at document open.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Nov 25, 2019 Nov 25, 2019

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

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Nov 25, 2019 Nov 25, 2019

Copy link to clipboard

Copied

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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Nov 25, 2019 Nov 25, 2019

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

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