Copy link to clipboard
Copied
I am trying to generating automatic numbering for a file each time it opens starting from 000501 then getting it to save the form after completion on exit. I enterred the code below:
if (this.documentFileName == "TFMC Work Order Form.pdf")
if (global.count == null) //checks to see if count exists
{
global.count = 000501 //sets initial count, you can change to suite your needs
global.setPersistent("count",true) //makes the counter a global object so it is persistent data
}
else
global.count++ //increments the the counter by one when the document is opened
var f = this.getField("Order Number").value = Number(this.getField("Order Number").valueAsString)+1; //creates a variable for the form field where the counter will be displayed
f.value = global.count //sets the form field to equal the counter
but it doesn't generate the number even if I start the field area with 501, howver if I go into prepare form the number sometimes runs a counter in the field 4, or 5. Auto generating only when I go into prepare form not always, only sometimes.
Can you assist?
Copy link to clipboard
Copied
Where does you use the script?
Copy link to clipboard
Copied
used the script in the javascript secion under tools.
Copy link to clipboard
Copied
This line doesn't make sense:
var f = this.getField("Order Number").value = Number(this.getField("Order Number").valueAsString)+1;
Especially not when followed by this:
f.value = global.count
Do you want to increment the value of the field by one, or set it to the value of the global counter?
Copy link to clipboard
Copied
I want to set the value of the inital counter as 501 then increment it by one every time it is opened.
Copy link to clipboard
Copied
Replace the last part of the code with just this:
this.getField("Order Number").value = global.count;
Copy link to clipboard
Copied
It still doesn't generate properly. It shows a numder then on occasion after several openings, that's when a new numbe displays.