Skip to main content
January 9, 2015
Answered

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

  • January 9, 2015
  • 12 replies
  • 87326 views

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 has been closed for replies.
Correct answer try67

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

12 replies

dustabor
Participant
May 12, 2015

This is exactly what i have been trying to figure out only i want a database on a server to hand out the numbers so that multiple people in the company can access my requisition form. I can't find much help on google (perhaps i'm not searching the right words or terminology) if anyone can point me in that direction, i'd appreciate it!

try67
Community Expert
Community Expert
May 12, 2015

It's not longer possible to connect a PDF to a local DB, unfortunately. You'll need to find some other way of doing it.

I recommend using a random number instead of trying to create a sequential one.

Participant
May 18, 2015

Hi try67,

could you help with something please?

I am using the your code to generate a new sales order number, everything working okay but my pdf has two pages page 1 the sales order page 2 T&Cs, when I switch between the tow the code changes? is there a way stopping that?

also I do not want my order number starting with 00 i just want a Radom 6 number without starting with 000

thank you

try67
Community Expert
Community Expert
January 9, 2015

It's certainly possible but you need to define very well when the field should become "locked". Do you want it to happen the moment the file is saved? The moment the file is opened? Submitted? Something else?

January 9, 2015

The moment the file is opened.

SanitySolutionsDEN
Participating Frequently
January 10, 2018

There's an error in your code. If you post it we could help you sort it out.


this is the javascript I added in Document JavaScripts:

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