• 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

50.8K

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 ,
Nov 18, 2013 Nov 18, 2013

Copy link to clipboard

Copied

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

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
Guest
Nov 18, 2013 Nov 18, 2013

Copy link to clipboard

Copied

Thank you so much. It worked.

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 ,
Apr 02, 2014 Apr 02, 2014

Copy link to clipboard

Copied

This solution works great if you save the form each time after the new number count is generated.

Is there a way to have a form do a +1 each time it is opened without having to save the form?

I want to be able to give a customer a bill of lading and each time they open the blank form it generates a new auto BOL number that is +1 from the last time they opened 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
LEGEND ,
Apr 02, 2014 Apr 02, 2014

Copy link to clipboard

Copied

How do you want the serial number field to act if the form has been assigned a serial number?

There are a lot of issues that need to be worked out for this to work well.

If the customer has it on his/her own machine how do you control the numbers across all your customers?

Will the form always be open on a machine that is always connected to the internet?

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 ,
Apr 02, 2014 Apr 02, 2014

Copy link to clipboard

Copied

It will be a unique identifier number for that document whether printed, saved or emailed.

It is a pdf form with submit buttons, so the form information can be submitted via email as well as saved to the users computer if they wish.

If the number happens to reset with a new user on a different computer that is fine. I have decided that each user will have another field to enter their initials or a number unique only to them that will prevent confusion on duplicate numbers. For example: AB4583 (hard coded #)-______ (unique number propagates here) - _____ (User enters their initials or # here)

The primary goals is for each individual user to be able to reopen the same blank form and not see the same number twice.

I read about global objects but the document was a little more advanced than my skill level and I was not sure how to proceed with that set up. It was also a fairly old article.

Thank you

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 ,
Jul 06, 2016 Jul 06, 2016

Copy link to clipboard

Copied

The script works great when opening the file. I am looking for a way to do a +1 every time the document is printed. Is there a way to do 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 ,
Jul 06, 2016 Jul 06, 2016

Copy link to clipboard

Copied

Move the code to the document's Will Print event, which you can find under Tools - JavaScript - Set Document Actions.

Edit: If you want the number to change after the file is printed use the Did Print event in the same location...

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 ,
May 27, 2017 May 27, 2017

Copy link to clipboard

Copied

Hello,

I'm trying to collect data about surgery results at 1 week, 1 month, 6 months.... is it possible to recover an autunumbered form so I can continue filling more fields?

for example. patient 1 - form assign 1 in id field, then I collect data of first week, but the form is already prepared for 1 month, 6 months, etc... Can I recover later the form number 1 so I con continue filling the rest of the form?

Thanks in advance

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
LEGEND ,
May 27, 2017 May 27, 2017

Copy link to clipboard

Copied

That choice is entirely with the form designer, you need to discuss your needs with them.

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
LEGEND ,
May 27, 2017 May 27, 2017

Copy link to clipboard

Copied

I would add some code to test if the "defaultValue" is empty and then add the serial number and if it is not empty then do not update the number. Your source document will have to be saved with the "defaultValue" of the field cleared.

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
Explorer ,
Apr 18, 2022 Apr 18, 2022

Copy link to clipboard

Copied

Hi!  Hopefully you are still helping others with PDF forms. 

 

I am also trying to do this- sequential numbering on a PDF form when it is opened a new number is genertated based on the previous number used.  I am not a programmer, and I am not really familiar with javascript.

 

I used the script that you provided as an answer to the post here- obviously I did not do something right.

 

This is what I used-

var f=this.getField("WORK ORDER");
f.value=002038(f.value)+1;
f.defaultValue=f.value;

 

I deleted -( not sure if I was supposed to)

function SEQ NUMBERS()
{
}

 

I will also attach a copy of my form.

 

Thank you in advance for your assistance.

 

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 ,
Apr 18, 2022 Apr 18, 2022

Copy link to clipboard

Copied

This line doesn't make sense:

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

What did you try to achieve there?

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
Explorer ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

As I said- I am not a programmer and not really familiar with javascript.  I thought that's where the starting number might go.

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
Explorer ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

I'm not exactly sure how it works.

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

It's not. And it's never a good idea to code by guessing... It's better to ask first, or read the documentation. Use the code as I provided it, only adjusting the field name in the first line, if needed.

The initial number should be placed as the default value of that field. However, the current code will strip any zeros from the start of it. If you want to include those the code will need to be adjusted.

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
Explorer ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Thank you.  I truly appreciate your time for people like me.

 

I don't necessarily need the zeros, so that's ok.  Where do I put the first number?  On my form- in the 2nd cell over from the WORK ORDER cell?

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

You should go to the field's Properties, then place the default value under the Options tab, like this:

 

try67_0-1650378812244.png

 

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
Explorer ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Ok.   So if I save that form, and name it 2038- when I open the orginal form shouldn't it advance to 2039?

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

You need to reset the file once first, but yes.

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
Explorer ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

I'm sorry- I don't know what that means, reset 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
Community Expert ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Tools - Prepare Form - More - Clear Form

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
Explorer ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

I guess I'm doing something wrong.  When I open the blank file again- the number remains the same.

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
Explorer ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

I got it! 

 

THANK YOU SO MUCH FOR YOUR TIME.

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
Guest
May 09, 2022 May 09, 2022

Copy link to clipboard

Copied

@VictoriaD  What did you end up doing to get it to work?  I have added the code, saved it as a new PDF and reset the file but the number never changes.

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