Automatic date field in a PDF

Community Beginner ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

I have utilized a java script to insert an automatic date/timestamp field in a PDF.  I was successful in doing that but it saved the form with the date/time. I want this to be blank each time it's opened and insert the date/time when someone has to fill out the form.

TOPICS
PDF forms

Views

148

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 ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

Where did you place the code? What triggers 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 ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

It's within Page Properties, Actions (Select a Java 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 ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

You need to move it to be a doc-level script, so that it only runs when the file is opened.

Place it under Tools - JavaScript - Document JavaScripts to achieve that. Do NOT place the code in a function, 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
Community Beginner ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

Thanks for your help with this. I tried that and it still did the same thing. Do I place in Document JavaScripts or All 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 Expert ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

Document JavaScripts.

What do you mean by "the same thing", exactly?

After you apply the code, clear the form and then save the file and close it. Then the field will be populated the next time you open 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 ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

It saves the date/time even though I clear if off and save. When I open the file again, it has a previous time on 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 ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

Post your code, and/or your file, please.

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 ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

var f = this.getField("Date/Time");

f.value = util.printd("m/d/yyyy h:mm tt", new Date());

 

Where does it pull the time from? Now it is inserting the time five minutes ahead of the time showing on my pc.

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 ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

No, it's not doing that. It's showing the current month instead of the minutes, though...

Change it to:

f.value = util.printd("m/d/yyyy h:MM tt", 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 ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

Ok, I tried that and it didn't insert the date or time.

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 ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

Does it need to be placed under 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 Expert ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

Yes 

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 ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

LATEST

I think I finally got this to work correctly! Thanks to all for your help on this!!

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 ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

Copy-paste this URL in Google Translate to see a nice tuto and get a nice sample file that will answer your question:

https://www.abracadabrapdf.net/ressources-et-tutos/js-et-formulaires-ressources/champ-date-automatiq...

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 ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

ok thanks, I will take a look.

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 ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

When I place it under Tools - JavaScript - Document JavaScripts it adds the pull down as pictured below. I do not want it to do that. It needs to auto fill the date / time when a person opens it.Harriet248032247zb1_0-1654885510741.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 ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

Set the field as Read-Only.

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