Skip to main content
Jan 9, 2015 5:11 PM UTC
Answered

How to get PDF to auto generate new invoice number everytime it is open

I need a unique invoice number to show in the corner of a form.  I was thinking of the best way (maybe the easiest?) to generate a number..  I want the form when opened to automatically create this number.  In addition, one the PDF has been filled out and so on, then saved, I dont want that invoice number to regenerate once its opened again for whatever the reason.  Does this sound possible?

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Jan 12, 2015 7:56 PM UTC

When I save and reopen a invoice number does not show. This is what (Ctrl +J) shows:

Thank you for helping me figure this out.


My bad... The code should be:

this.getField("Invoice No").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));

139 replies

Participant
Apr 30, 2024 3:19 PM UTC

I need help. I have been reading all the threat and I'm still not getting the pdf auto generate the number. Can someone explain me how to do it? I'm newby, but I need to create a PDF that can generate the number when its open.  Thank you in advanced!

Translate
Inspiring
Sep 16, 2022 2:11 PM UTC

I need to add unique invoice number to a form that will auto-populate the new number every time the form is saved. The number needs to be 2022-IN-20000 with the new number following as 2022-IN-20001 and so forth. Can anyone help? Thanks

Translate
Participant
Sep 11, 2022 6:46 AM UTC

hi there, 

can somebody help me to creat a new PDF Invoice Form which it will automate the invoice numbering for every new invoice. 

 

 

thanks in advance. 

Translate
Participant
May 17, 2019 5:06 PM UTC

Is it possible to "Lock" and "Unlock" the automatically generated invoice number? Thank you.

Translate
Participant
Aug 1, 2018 10:10 PM UTC

Hello i'm a novice when it comes using the PDF unique numbers, and the code. I have multiple log in portals that are assigned to different team members. When a member logs in I want to have a unique id populate. Will the methods that have been explained work for me in this instance or will I run into trouble since their are multiple portals utilizing the same PDF?

Once the PDF is filled out I have a submit button that will e-mail the PDF to the correct party members. At this point I want the unique number to be saved in my DB so it won't be utilized again.

Am I in over my head here, or is this something I can easily accomplish? Or would making a single portal with one user name and one password be the necessary route to accomplish the process?

Any advice and or assistance will be greatly appreciated. Thank you in advance. This article has already been extremely helpful in my form.

Translate
try67
Community Expert
Community Expert
Aug 1, 2018 10:16 PM UTC

You can use the code above to generate random invoice numbers.

You can then export the form data and import it into your DB, but you can't prevent duplicates from happening (at least not at the PDF level). However, if you use a long random number (for example, 10 digits long), the chances of that happening are minuscule.

Translate
Participant
Aug 2, 2018 1:43 PM UTC

Could I link the log in portals to start the invoice number with letters specific to the user? Example: ms-10010001 or bg-10010001 so only my numbers could be duplicated but they would still be unique since the serial has a static value?

Thank you for responding so quickly...This thread has been extremely useful for this process.

Translate
Ty3ap
Participant
Apr 13, 2018 6:36 PM UTC

I use"Fill and sign pdf forms" in my android device , what script need to use becose in this soft. Have only save buton, and when i click change original file name.(Maybe need me when save , or save as file)

Translate
Cheerful_Serenity5CF8
Participant
Oct 6, 2017 7:30 PM UTC

I entered the code, but it does not automatically change the number.  I have to go into the calculation field in the form, open/close, save and then I get a new number.  This is the code I used.

  1. this.getField("Number")=util.printf("%06d",Math.floor((Math.random()*500)+1));
Translate
try67
Community Expert
Community Expert
Oct 6, 2017 8:17 PM UTC

You should not use the code as a calculation script, but as a doc-level script.

Translate
Cheerful_Serenity5CF8
Participant
Oct 6, 2017 8:39 PM UTC

I tried it there too. Still does not auto populate the numbers.

Translate
chrism53001470
Participating Frequently
Feb 28, 2017 11:16 PM UTC

Thank you very much try67 you have saved me many many hours (or milliseconds).

Translate
AndrewCollingwood
Participating Frequently
Dec 1, 2015 5:07 PM UTC

Hey all

I am novice when it comes to adobe so hopefully someone can help me out.  Try67 already got me most of the way with his help and thank you for that but I need one last fix.  I have used this code this.getField("INVOICE").value = Number(this.getField("INVOICE").value) + 1; to make my invoice numbers go up by one every time I open it and it works great.  Now I have the problem of when I save as and rename the invoice to lets say 1001 I want that one to lock but as of now when I open 1001 it adds another number to it and changes it to 1002.  I was hoping that the original pdf will add by one but any copies will be locked down.  I have no idea how to define that.  Any help would be appreciated.

Andy

Translate
try67
Community Expert
Community Expert
Dec 1, 2015 5:30 PM UTC

You need to clearly define the conditions under which the field should update, and when it shouldn't.

Translate
AndrewCollingwood
Participating Frequently
Dec 1, 2015 5:37 PM UTC

I know I need to do that but where do I do that and how is my question.  I do not have very much experience in adobe products and I am trying my best to figure things out but I am not finding much information on this other then this thread.  I am assuming that I need to add something into the document actions area but I am not sure what to write.  I would like it to save and lock the invoice number

Translate
leslies51990429
Participating Frequently
Jun 18, 2015 1:01 PM UTC

Hi try67! This feed has been incredibly helpful. How would I modify the script below to make it start at 00000 or 00001 (it's currently starting at 837729)

  1. var v = +this.getField("Counter").valueAsString; 
  2. this.getField("Counter").value = util.printf("%06d", (v+1));

What I'm trying to do is create a root form with auto-updating work order numbers, that can be saved as separate files, while the root form still increases with each use. If I save the root form after modifying it, then when I open it the next time, the number increases. But if I save it as a separate file, the root form number doesn't change the next time I open it. Is this possible?

Translate
try67
Community Expert
Community Expert
Jun 18, 2015 1:21 PM UTC

Just clear the value of the field (or set it to "0") and it will continue from there...

If you don't want the number to change you need to edit the file and remove the script, or flatten the form fields (but then the script will produce an error message), or define some kind of condition as to when the value needs to be incremented and when it shouldn't be.

Translate
leslies51990429
Participating Frequently
Jun 18, 2015 7:27 PM UTC

Well that was just too easy. Thank you for your help with this!

Translate