Copy link to clipboard
Copied
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?
My bad... The code should be:
this.getField("Invoice No").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Copy link to clipboard
Copied
Remove the semi-colon after the if-statement.
Copy link to clipboard
Copied
I get an error "The value entered does not match the format of the field (Invoice)
Copy link to clipboard
Copied
Remove the formatting from the field.
Copy link to clipboard
Copied
This worked great!!!! wondering how to get it to start at a certain number and count sequentially from that number? Trying to create a Invoice with Sequential numbers for accounting purposes.
Copy link to clipboard
Copied
The easiest thing to do is to setup the global.count variable in the console window.
global.count = 500;
Copy link to clipboard
Copied
Hello! I have the same issue. I was wondering what is the code if I want it to generate a new number every time it is submitted through an action button? My document is an order form for a single customer and I need to have a unique PO number created every time they send it to us.
Thanks!
Copy link to clipboard
Copied
Addendum: I am getting the error code:
ReferenceError: invalid assignment left-hand side
1:Document-Level:PO number
ReferenceError: invalid assignment left-hand side
1:Document-Level:PO number
ReferenceError: invalid assignment left-hand side
1:Document-Level:PO number
Copy link to clipboard
Copied
There's an error in your code. If you post it we could help you sort it out.
Copy link to clipboard
Copied
this is the javascript I added in Document JavaScripts:
this.getField("PO Number") = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Copy link to clipboard
Copied
Change it to:
this.getField("PO Number").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Copy link to clipboard
Copied
I've followed this entire thread from the first question to the last reply and I'm almost there for what I want to do. (I think).
We have a Bill Of Lading (BOL) pdf form with multiple fields to fill. We want to create a sequential BOL number for each BOL so we have something to track and identify.
Following the scripts you've suggested here, I've managed to get the form "template" to create the BOL number sequentially. However, when I save the template out to a particular filled in BOL, the new file number increases when I open it (these are emailed so this is very not good - LOL). Further, the "template" file increases by 2 when I reopen to create another BOL.
Am I asking for too much? I want a template BOL that generates BOL numbers, sequentially, so that once created the newly created BOL pdf keeps the number it has (remains static) and the template BOL pdf increases only by one digit when it's opened.
Copy link to clipboard
Copied
You need to clearly define under what conditions the number should change, and should not change.
Copy link to clipboard
Copied
Hi,
I found where you had answered a question about auto-numbering code for pdf documents. I copied your answer to another person and got the number to auto generate, in sequence and without leading zeros, but I need it to stop changing once saved. Your prior code stops at the print function. I am NOT a programmer at all so if you answer this message please use easy language and small words...LOL! Thank you!
Copy link to clipboard
Copied
try, I have a form which I built in Livecycle a few years back which auto generates new numbers in increments of 1 every time it's saved. However, if the form is cleared using the "clear form" option the control number is also deleted so I have to start back at 1. I need the form which a waybill to have a unique control number every time I use it without worrying about the numbers being reset. Is there a way to prevent this? I'm using FormCalc for the language with a the following calculation.
form1.#subform[0].Control_Number[0]::preSave - (FormCalc, client)
$ = this + .25;
The waybill is a 4 page document which is why I've set the number added to .25. Can you help with this?
Copy link to clipboard
Copied
You need to set the field's default value to prevent that. I don't know how you do that in an LCD form, though.
Try asking here: LiveCycle Designer
Copy link to clipboard
Copied
HI Try67
I been working on this since 2 weeks today
I am trying to create a pdf that should generate a unique requisition number
only after the user hit the submit button.
For example: User A filled the PDF form, then he hit submit button.
then the form will be sent to 3 managers, if any of the 3 managers opens
the pdf file they should see a requisition number generated automatically.
Does that makes any sense?
Copy link to clipboard
Copied
One of the problems with creating unique numbers for a PDF is that to this you need a unique event on which to do it. If one of the scripts provided in previous posts is placed in a document script, then every time the PDF is opened it will create a new number. But what you really want is for this number to be generated once per form use. So how do you do that? Solutions provided in previous posts to this thread suggest generating the number on a submit. This is a excellent idea since the submit represents the completion of the form.
Another way to do this is to create a reset button and generate the number on form reset. Since "reset" represents the beginning of the form filling process.
The important bit here is that JavaScript can't read the user's mind to know their intention, so whether or not to generate the number. Its your form, you create the usage model, and so you have to decide what unique event is going to be used to generate the form number.
Copy link to clipboard
Copied
Hi Try,
I am hoping you are still contributing to the community as this thread looks older. I have created a randomly generated number in a form field and it works great; up until the point that I rest the form. After I hit the reset button on the form the field that generates a random number remains blank. How can I alter the Java to a generate the number after resetting the form? Here is the code I am using at the Document Level:
this.getField("O&SA_ID").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Any help with this would be greatly appreciated.
Cheers,
Mark
Copy link to clipboard
Copied
Add your script to a "Run a JavaScript" action on the reset button.
Copy link to clipboard
Copied
Hello try67,
Can you help me with the code to have the number change only when the pdf is saved? I have a master template for a voucher. Each time fields are filled in and then saved, I need the voucher number to update. In the past we have printed vouchers with sequential numbering to track the vouchers. We're trying to move to an electronic voucher system where the form is pdf fillable and the number updates each time the voucher is saved.
Copy link to clipboard
Copied
Can you help me with the code to have the number change only when the pdf is saved? I have a master template for a voucher. Each time fields are filled in and then saved, I need the voucher number to update. In the past we have printed vouchers with sequential numbering to track the vouchers. We're trying to move to an electronic voucher system where the form is pdf fillable and the number updates each time the voucher is saved.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
What code did you use, and where did you place it?