Copy link to clipboard
Copied
I can not seem to figure out how I can insert a random number generator into a work order form that I have already created and put all other required field items into. I am not savy when it comes to any of the JavaScript stuff. I need the number to be (4) digits and I need it to re-generate on each new form after it is filled out and saved or upon opening a new one. any step by step help would be greatly appreciated!
Copy link to clipboard
Copied
You want it to change the number after the form is saved? That will just mean it will be lost, unless the user re-saves the form (which will cause a new number to be generated, etc.). I think the best is to do so before the file is sent.
To do so you can use the following code (let's say you want to place it in a text field called "Unique ID"):
this.getField("Unique ID").value = Math.random().toString().substr(2,4);
Keep in mind you could get duplicates, though. There's a 0.1% chance of getting a duplicate number the second time you generate it, and the more you use it, the higher that number becomes.
Copy link to clipboard
Copied
Sorry, 0.01%...
Copy link to clipboard
Copied
sorry for the wording Try67. what I meant was id want it to generate a new number each time it is opened (as a blank) work order form. im confused on where exactly to input any of these codes.
Copy link to clipboard
Copied
So you want to only populate the field if it's empty? The go to Tools - JavaScript - Document JavaScripts and create a new item (let's call it "scripts"), with the following code (delete the code that is generated by default when you open the editor window):
if (this.getField("Unique ID").valueAsString=="")
this.getField("Unique ID").value = Math.random().toString().substr(2,4);
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more