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.
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());
Copy link to clipboard
Copied
"Does not work" is not very helpful... What exactly happened when you tried it?
Copy link to clipboard
Copied
It does not populate current date
Copy link to clipboard
Copied
Again, this is not very helpful. You need to provide exact details.
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.
Copy link to clipboard
Copied
Can you share the file?
Copy link to clipboard
Copied
See attached file. I removed the content for proprietary protection.
Copy link to clipboard
Copied
This is a screenshot of the file. You need to share the ACTUAL file.
Copy link to clipboard
Copied
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());
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());
Copy link to clipboard
Copied
Thank you. I'll try that and I'll let you know if it works.
Copy link to clipboard
Copied
Hello try67. It is finally working. The document populated a current date. Thank you! You're the man!
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!
Copy link to clipboard
Copied
Delete the function definition, or add this to the end of your code:
load();
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.
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.
Copy link to clipboard
Copied
What PDF viewer are you using?
Not all PDF viewers support document level scripts.
Copy link to clipboard
Copied
How do I set default value as today's date in Date picker. Please help
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?
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.
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.
Copy link to clipboard
Copied
How do I go to doc level script?
Copy link to clipboard
Copied
Tools - JavaScript - Document JavaScripts.
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.