Skip to main content
Participant
August 13, 2023
質問

Auto numbering every time a fillable pdf form opens and saves a file with the new number each time

  • August 13, 2023
  • 返信数 2.
  • 2270 ビュー

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?

このトピックへの返信は締め切られました。

返信数 2

try67
Community Expert
Community Expert
August 13, 2023

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?

 

Participant
August 15, 2023

I want to set the value of the inital counter as 501 then increment it by one every time it is opened.

try67
Community Expert
Community Expert
August 15, 2023

Replace the last part of the code with just this:

this.getField("Order Number").value = global.count;

Bernd Alheit
Community Expert
Community Expert
August 13, 2023

Where does you use the script?

Participant
August 15, 2023

 used the script in the javascript secion under tools.