Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
That works perfectly! THANK YOU!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
- Yes.
- Yes, unless you add some additional condition to it.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now