Skip to main content
Participant
March 2, 2018
Answered

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

  • March 2, 2018
  • 1 reply
  • 17174 views

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.

This topic has been closed for replies.
Correct answer try67

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.

1 reply

try67
Community Expert
Community Expert
March 2, 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?

jayb214Author
Participant
March 2, 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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 2, 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.