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

dustabor
Participant
May 12, 2015 1:53 PM UTC

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!

Translate
try67
Community Expert
Community Expert
May 12, 2015 2:08 PM UTC

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.

Translate
Participant
May 18, 2015 5:01 PM UTC

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

Translate
try67
Community Expert
Community Expert
Jan 9, 2015 6:13 PM UTC

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?

Translate
Jan 9, 2015 6:52 PM UTC

The moment the file is opened.

Translate
try67
Community Expert
Community Expert
Jan 9, 2015 8:27 PM UTC

Do you want the number to remain even if the rest of the form is cleared?

Translate