Copy link to clipboard
Copied
Hello,
I am in the process of creating a contract template for our company. We would like to be able to send this document out to our customers for them to sign. I would like to assign a different contract number to each document that I resave (save as) under a customer's name. Everytime I do this I would like to have the contract start with a new distinct contract number. I will be working off of the master template (file). I would like the number to start with 100001. Currently, I am using this JavaScript but it is only putting one digit at a time. I started with a 1, then number 2, now I am at number 3. Only one single digit. My field is titled Agreement Number. Can you please help me with a solution?
var f = this.getField("Agreement Number");
if (f.value=="") f.value = "100001";
else f.value = util.printf("%04d", (Number(f.value)+1));
Copy link to clipboard
Copied
Search JavaScript in the tools search then click Document JavaScripts, then name the script and copy and paste the script. When you close the window the field will advance by 1. Clear the field and save the PDF. The number will advance every time you open it.
Copy link to clipboard
Copied
Copy and paste the script exactly. Then change "Template.pdf" to whatever your file name is and include the .pdf file extension.
Copy link to clipboard
Copied
Your script advances the number by 1. What would you like it to do?
Copy link to clipboard
Copied
I want it to display 100001 on the document and so forth. (100002) But I want it to show the next number in the sequence each time I save a copy and rename it.
Copy link to clipboard
Copied
Where is your script located? You should enter it as a document level script with a test to make sure the file name is "Template.pdf" - or whatever you're calling it. That way, once the file is saved under a different name, the script won't advance the number when the new contract is re-opened. Also, upon opening the template you should immediately save it so the new number is saved in it. Every time you open the template the number will advance by 1 (save the template, then "Save As" with a different name). Here's the document level script (than runs every time the doc is opened):
if(this.documentFileName=="Template.pdf")
{
var f = this.getField("Agreement Number");
if (f.value=="") f.value = "100001";
else f.value++;
}
You don't need the util.printf script if you format the field as a number with no seperator and no decimal places.
Copy link to clipboard
Copied
I have it listed under Customer Calculation Script under the Calculate tab. As well as Run Custom Validation Script under the validate tab. In the Actions tab I have Mouse Enter, Run a JavaScript.
Copy link to clipboard
Copied
Remove all of those scripts and enter it where I said.
Copy link to clipboard
Copied
Sorry I don't see where you said to remove and add. I see a post saying "You don't need the util.printf script if you format the field as a number with no seperator and no decimal places." Can you please clarify? Thanks
Copy link to clipboard
Copied
Sorry I see it now.
Copy link to clipboard
Copied
Sorry, where does the script go, i'm not sure where the document level script goes. Can you please clarify?
Copy link to clipboard
Copied
Search JavaScript in the tools search then click Document JavaScripts, then name the script and copy and paste the script. When you close the window the field will advance by 1. Clear the field and save the PDF. The number will advance every time you open it.
Copy link to clipboard
Copied
I followed these steps but it still doesn't want to update when I save and then create another. I close the file and only 100001 appears in the field. Do I need to leave the parenthesis in the script when referring to the file name and the field name?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi! I used this code for my document as well and it works on my computer, but I need it to work on mobile devices as well. I'm running into an issue where this code isnt running itself when used on phones either in the abode app or in a browser.
Copy link to clipboard
Copied
JavaScripts supported by mobile PDF viewers are very limited.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now