Skip to main content
January 9, 2015
해결됨

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

  • January 9, 2015
  • 12 답변들
  • 87326 조회

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?

이 주제는 답변이 닫혔습니다.
최고의 답변: 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 답변

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.

January 9, 2015

Then you can just use this code (adjust the field name, of course):

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


Do I put it in the Custom calculation script. Sry for all the questions I am a real newbie to this.