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

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

Views

320

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

Copy link to clipboard

Copied

Use the script at document open.

Votes

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
Community Expert ,
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

Votes

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
Community Expert ,
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

Votes

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
Community Expert ,
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);

Votes

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