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

How to add a field that generates a date/time stamp in mmddyyyyhhmm

New Here ,
Mar 02, 2018 Mar 02, 2018

Hi,

I need to create a form field that generates a document number in the form of date & time the form was created/opened or saved. Ideally, it would be in the format "mmddyyyyhhmm" and the field/text would look like the rest of the fields in the document (the default for acrobat pro). Dynamic stamps don't seem to be what I'm looking for since they cannot be customized to that extent from what I gather (I could be wrong?). I'm not too familiar with java to know what type of code to try. Any help would be appreciated.

Thank you.

TOPICS
PDF forms
16.8K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Mar 02, 2018 Mar 02, 2018

OK. Then create a (read-only) text field for this number. Let's say it's called "TimeStamp".

Then go to Tools - JavaScript - Document JavaScripts and create a new item ("scripts" or whatever) and paste this code into it:

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

if (f.valueAsString=="") f.value = util.printd("mmddyyyyHHMM", new Date());

Press OK and the field will be populated. You can reset the form and save the file, and then you're done.

View solution in original post

Translate
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 ,
Mar 02, 2018 Mar 02, 2018

Actually, a stamp can do it, but there's no point in using one if you want it to appear at a fixed location.

So what should trigger the field being filled-in? Saving the file? Printing it? Opening it? And should its value change the next time the file is saved/printed/opened?

Translate
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 ,
Mar 02, 2018 Mar 02, 2018

The trigger would be opening the file, and the generated number should never change once it's created. It would basically serve as a document request number.

Translate
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 ,
Mar 02, 2018 Mar 02, 2018

OK. Then create a (read-only) text field for this number. Let's say it's called "TimeStamp".

Then go to Tools - JavaScript - Document JavaScripts and create a new item ("scripts" or whatever) and paste this code into it:

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

if (f.valueAsString=="") f.value = util.printd("mmddyyyyHHMM", new Date());

Press OK and the field will be populated. You can reset the form and save the file, and then you're done.

Translate
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 ,
Mar 02, 2018 Mar 02, 2018

That works perfectly! THANK YOU!

Translate
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 03, 2019 Oct 03, 2019
Hello -- i tried following instructions above on an Adobe Pro software, but it did not show any results. I copied and pasted the code, but before doing that, I removed this default code. See below. Should I keep it?" function scripts() { }" ?
Translate
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
Explorer ,
Jan 05, 2022 Jan 05, 2022

Would it be possible to use this code but for when a submit/email button is used? Also if this is possible would it change every time the button is used?

Translate
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 05, 2022 Jan 05, 2022

- Yes.

- Yes, unless you add some additional condition to it.

Translate
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
Explorer ,
Jan 05, 2022 Jan 05, 2022

excellent, I would like it to date stamp the form every time the submit button is used. Would the code use the:

 

"util.printd"

 

Or would it be something else as it is a button?

 

 

Translate
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 05, 2022 Jan 05, 2022
LATEST

Exactly the same as above, just place it under the Mouse Up event of your button field.

I would recommend you do the submit command using a script as well, though, otherwise you can't guarantee the script will execute before it, even if you add it first.

Translate
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