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

How to create sequential number field?

Guest
Nov 17, 2013 Nov 17, 2013

Copy link to clipboard

Copied

I have created a pdf file and I'd like to have a field with sequential numbers.

For instance, if I open my pdf now and it has number 1 in the field, 'd like to have number 2 in the field the next time that I open the file, and so on...

Views

48.0K

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

correct answers 1 Correct answer

Community Expert , Nov 18, 2013 Nov 18, 2013

Go to Tools - JavaScript - Document JavaScripts and create a new script with the following code (remove any default code that's inside the window when you first open it):

var f = this.getField("Serial Number");

f.value = Number(f.value)+1;

f.defaultValue = f.value;

Of course, you'll might need to adjust the field name in the first line of code.

Votes

Translate

Translate
Community Expert ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

Yes, like this:

 

var prefix = "23-";
if (this.documentFileName=="Original file name.pdf") {
	var num = this.getField("Text2");
	num.value = prefix  + Number(num.valueAsString.replace(prefix, ""))+1;
	num.defaultValue = num.valueAsString;
}

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 ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

I copied this Java Script and changed the one I already had, and it is not changing anything. Now the number won't increase and the 23 - is not showing up.

 

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 ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

Also, one other question. I have probably a dozen techs that would need to use this form now with the ticket number auto-generating itself. Correct me if I'm wrong, but I would need to put this in either a cloud setting or on a server where everyone could access the same form, so that the numbering sequence continues to change, correct?

 

Thanks,
Nick

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
Community Expert ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

Are these any error messages when you open the file? Press Ctrl+J to open the Console window.

 

No, that won't work, unless all the users only use a single copy of the file. If it's on a cloud it will mean they have to download it first to their computers, then upload it back when done, which will overwrite any other file that has been uploaded. And if it's on a shared folder they would either need to download it (same issue as with the cloud) or work on it directly there, which would lock the file and prevent any other users from saving 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 ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

TypeError: num is null 2:Document-Level:TICKET NUMBER TypeError: f is null 3:Page:Open TypeError: num is null 2:Document-Level:TICKET NUMBER TypeError: num is null 2:Document-Level:TICKET NUMBER TypeError: f is null 3:Page:Open TypeError: num is null 2:Document-Level:TICKET NUMBER TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: 1 is not a function 2:Document-Level:TICKET NUNMBER TypeError: 1 is not a function 2:Document-Level:TICKET NUNMBER TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open SyntaxError: syntax error 3: SyntaxError: syntax error 2: SyntaxError: syntax error 2: SyntaxError: syntax error 1: TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open SyntaxError: missing } in compound statement 5: TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open TypeError: f is null 3:Page:Open

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 ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

When I open the file, I do not get any errors. The new script you sent over does not have the numeric value increasing at all when the form is opened. 

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
Community Expert ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

Can you share the file?

 

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 ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

Please see attached

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
Community Expert ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

It does update, although you have an error in the Page Open script of page 1 (because there's no field called "Today" in the file). However, there is a small mistake in the code I gave you.

Change this line:

num.value = prefix + Number(num.valueAsString.replace(prefix, ""))+1;

To:

num.value = prefix + (Number(num.valueAsString.replace(prefix, ""))+1);

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 ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

I must be doing something wrong because after making the change you recommended above, I still can not get any sequential number to exist, mush less the year in front of it. This is the script that I am running:

 

var prefix = "23-";if (this.documentFileName=="Utility Service Ticket v2022-01.pdf") {var num = this.getField("TICKET NUMBER"); num.value = prefix +(Number(num.valueAsString.replace(prefix, ""))+1); num.defaultValue = num.valueAsString; }

 

If I go back to the original script you gave me, that works. The minute that I take out the original script, and put in the newly revised script to reflect the year, then the sequential number, everything stops working. Any thoughts?

 

Thanks,

Nick

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
Community Expert ,
Dec 13, 2022 Dec 13, 2022

Copy link to clipboard

Copied

Works fine for me... See attached.

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 ,
Dec 13, 2022 Dec 13, 2022

Copy link to clipboard

Copied

Clearly, I was doing something wrong. I will go in and see what I was doing wrong.

 

What would be your recommendation for dispersing this company-wide so that everyone is drawing off the same service ticket? I want all the service techs to use the same ticket so the numbering sequence can be accurate and not have duplicate service ticket numbers. Our company has a server on which I could put the ticket, so all the techs could access the service ticket from one centralized place. Would that work? 

 

Thanks,

Nick

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
Community Expert ,
Dec 13, 2022 Dec 13, 2022

Copy link to clipboard

Copied

I would recommend you use a time-stamp or random numbers for that. If you want to use sequential numbers you must do so in a single location, for example on an admin's computer, after the forms have been filled in.

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 ,
Dec 13, 2022 Dec 13, 2022

Copy link to clipboard

Copied

The random numbers would work as well. Can I incorporate the 23- into a random number instead of the sequential? Can you help me out with a script for that?

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
Community Expert ,
Dec 14, 2022 Dec 14, 2022

Copy link to clipboard

Copied

LATEST

You can use this line:

 

num.value = prefix + Math.floor(Math.random()*100000);

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