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

JavaScript Help Needed

New Here ,
Jun 07, 2024 Jun 07, 2024

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));

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , Modern Acrobat , PDF , PDF forms

Views

175

Translate

Translate

Report

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
Engaged ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

Your script advances the number by 1.  What would you like it to do?

Votes

Translate

Translate

Report

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
New Here ,
Jun 07, 2024 Jun 07, 2024

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.  

Votes

Translate

Translate

Report

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
Engaged ,
Jun 07, 2024 Jun 07, 2024

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.

Votes

Translate

Translate

Report

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
New Here ,
Jun 07, 2024 Jun 07, 2024

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.  

Votes

Translate

Translate

Report

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
Engaged ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

Remove all of those scripts and enter it where I said.

Votes

Translate

Translate

Report

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
New Here ,
Jun 07, 2024 Jun 07, 2024

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

 

Votes

Translate

Translate

Report

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
New Here ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

Sorry I see it now.  

Votes

Translate

Translate

Report

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
New Here ,
Jun 07, 2024 Jun 07, 2024

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?  

Votes

Translate

Translate

Report

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
Engaged ,
Jun 07, 2024 Jun 07, 2024

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.

Votes

Translate

Translate

Report

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
New Here ,
Jun 07, 2024 Jun 07, 2024

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?

Votes

Translate

Translate

Report

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
Engaged ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

LATEST

Copy and paste the script exactly.  Then change "Template.pdf" to whatever your file name is and include the .pdf file extension.

Votes

Translate

Translate

Report

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