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

how do i populate a form with current date?

Community Beginner ,
Mar 31, 2016 Mar 31, 2016

Copy link to clipboard

Copied

I tried the instructions below but it does not work:

In Acrobat:

The script you create to display the current date when the document is opened is a document level script.

To create an automatic date field:1. Select Tools > Forms >. Edit > Add New Field > Text Field and create a text field. (For more infor-mation, see the section on Creating Form Fields in the Acrobat online help.) Select All Properties > General tab and name the field Today.

2. Select the Format tab, chooses Date for the format category, and chooses a month, day, and year format option (for example, “mmm d, yyyy”). On the General tab, make sure the field is read-only because it will be a calculated field, and click Close.

3. To create a document level script that is executed each time the document is opened, choose View > Tools > Document Processing > JavaScript > Document JavaScripts. Name the script Today, and click Add.

4. Delete the automatically generated text, defining a Today function, that is displayed in the script window. Type in the following text in the exact format (line wraps are OK) and click OK.

var f = this.getField("Today");f.value = util.printd("mm/dd/yyyy", new Date());

This script binds the Today field to the variable f, and then calculates the value. The newDate() ex-pression creates a new date object initialized to the current date and time. The util object is used to format the date into the month/day/year format.

5. Click OK in the JavaScript Edit dialog box, and then click Close in the JavaScript Functions dialog box.

TOPICS
Acrobat SDK and JavaScript

Views

48.9K

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

correct answers 1 Correct answer

Community Expert , Apr 05, 2016 Apr 05, 2016

The advice you were given above was misleading. You should not have just removed the "var f" part of the code. It broke it. Put it back and if you want to update the field also before the file is printed place it under Tools - JavaScript - Set Document Actions - Document Will Print as well.

The correct code is:

var f = this.getField("Today"); f.value = util.printd("mm/dd/yyyy", new Date());


Or:

this.getField("Today").value = util.printd("mm/dd/yyyy", new Date());

Likes

Translate

Translate
Community Expert ,
Mar 31, 2016 Mar 31, 2016

Copy link to clipboard

Copied

"Does not work" is not very helpful... What exactly happened when you tried it?

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
Community Beginner ,
Apr 04, 2016 Apr 04, 2016

Copy link to clipboard

Copied

It does not populate current date

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
Community Expert ,
Apr 04, 2016 Apr 04, 2016

Copy link to clipboard

Copied

Again, this is not very helpful. You need to provide exact details.

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
Community Beginner ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

Hi try67. Populating current date is what I'm trying to achieve. Following directions above didn't help as the document becomes stagnant from the date I did it. It should change current date everyday, for example when you print the document, it would reflect the current date. In this case, it failed to do it.

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
Community Expert ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

Can you share the file?

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
Community Beginner ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

See attached file. I removed the content for proprietary protection.Doc Sample.PNG

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
Community Expert ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

This is a screenshot of the file. You need to share the ACTUAL file.

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
Community Beginner ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

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
LEGEND ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

You need to change this line:

this.getField("Today");

To this:

var f = this.getField("Today");

Or better yet, replace the entire script with this one line:

getField("Today").value = util.printd("mm/dd/yyyy", new Date());

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
Community Expert ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

The advice you were given above was misleading. You should not have just removed the "var f" part of the code. It broke it. Put it back and if you want to update the field also before the file is printed place it under Tools - JavaScript - Set Document Actions - Document Will Print as well.

The correct code is:

var f = this.getField("Today"); f.value = util.printd("mm/dd/yyyy", new Date());


Or:

this.getField("Today").value = util.printd("mm/dd/yyyy", new Date());

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
Community Beginner ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

Thank you. I'll try that and I'll let you know if it works.

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
Community Beginner ,
Apr 06, 2016 Apr 06, 2016

Copy link to clipboard

Copied

Hello try67. It is finally working. The document populated a current date. Thank you! You're the man!

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
New Here ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

This isn't working for me. I created a text field, named it "Today", created a Document Script and set the field's value per your answer. Nothing happens. I've tried saving the PDF and reopening it to see if that would get things working, but nothing.

I have had Adobe Acrobat Pro DC for about a day now, so I'm definitely fresh. I have version 2019.008.20071. Let me know if you need more info from me, thanks in advance!

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
Community Expert ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

Delete the function definition, or add this to the end of your code:

load();

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
LEGEND ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

You're working with an Adobe Sign form, not a regular Acroform, so the field name isn't what's shown in the Name field of the Properties dialog. You can see the actual name in the fields list in the right-hand pane, but the script won't work when used with Adobe Sign anyway. It will work if you convert to a regular Acroform though.

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
New Here ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

Thank you so much try_67 and George_Johnson! I removed the function definition and updated the Javascript to look for the actual name and it worked! Thanks for getting back to me so quickly, your help is very much appreciated.

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
LEGEND ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

What PDF viewer are you using?

Not all PDF viewers support document level scripts.

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
Community Beginner ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

How do I set default value as today's date in Date picker. Please help

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
LEGEND ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

You're going to have to provide more details. For example, do you want to have it default to the current date only if the field is blank at the time the user is interacting with the field, or something else?

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
Community Beginner ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

Yes, default value as todays date in date picker when the user open the form and also have ability to change it later if he wants.

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
Community Expert ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

Add this code as a doc-level script (not in a function):

this.getField("Date1").defaultValue = util.printd("mm/dd/yyyy", new Date());

Change the field name and date format as needed.

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
Community Beginner ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

How do I go to doc level script?

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
Community Expert ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

Tools - JavaScript - Document JavaScripts.

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
Community Beginner ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

I did that and it's not working for date picker.

I works for Text box and not date picker.

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