Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
22

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

Community Beginner ,
Aug 13, 2023 Aug 13, 2023

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?

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , PDF , PDF forms
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2023 Aug 13, 2023

Where does you use the script?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 14, 2023 Aug 14, 2023

 used the script in the javascript secion under tools.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2023 Aug 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?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 14, 2023 Aug 14, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2023 Aug 15, 2023

Replace the last part of the code with just this:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 28, 2023 Aug 28, 2023
LATEST

It still doesn't generate properly. It shows a numder then on occasion after several openings, that's when a new numbe displays.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines