How do I make a form that generates a unique number when the form is saved?
Hi, please i was searching the community and i came across a question and answer that is close to mine,
Here is the question i fund by another member:
I need to make a form that generates an individual unique number on the form when it is saved. These are forms that are used throughout the company for chegue requests and other expenditures and need to be sent to an accounting department. Each form will require a unique number for accounting purposes, but the master form will be located on a central site to be downloaded numerous times by numerous locations. I then will need to have that field locked once the form is being saved so the number cannot be changed. Any suggestions?
And here is the suggested solution by By "Eugene Williams"
You can add a mouse down event to lock the form and a mouse up event to submit the form.
To Use this Script, add a Text Field to the PDF and name it "SeqFormID". If desired, place a seed value in the field. This example uses a pure number, so place any number in the field. Make this field ReadOnly and position it in a convenient location (top or bottom of page). Then duplicate the field to all pages where the Form ID will be displayed. It's a good idea to make sure the field looks good (font size, color, border, etc.) and is large enough before duplicating it.
Modify this script by changing format and the method for incrementing the Form ID. This technique can be generalized for use with distributed forms by acquiring the ID from an internet source or by using a random number technique to generate the number.
Code: // Get and increment Form ID
this.getField("SeqFormID").value++;
You can add the code to increment to the MouseUp event of your button (instead of the pageOpen event).
If your sequence number has to span multiple work sessions with the form, you'd have to make sure that the form file is always updated. Saving using JavaScript is a little bit of a mess, for "security reasons", so, the easiest might be to pop up a reminder to save. Otherwise, if you want to save the form "silently", you would have to set up a so-called trusted function which does the saving.
One more thing to be aware of is that the sequence number must not be reset when you reset the form. This is, however, easy to overcome… you would not only set the value of the field, but also its defaultValue when you increment it That would look like this:
this.getField("mySequenceID").value ++ ;
this.getField("mySequenceID*).defaultValue = this.getField("mySequenceID").value ;
Now here is mine,
Mine is an Invoice page that i want to generate an individual unique id on the invoice page when it is opened. This invoice page when filled, printed, save/submitted will be issued to customer and a duplicate sent to the accounting department, the reason for the accounting department duplicate is to be able to reconcile the customer’s invoice copy and the accounting department duplicate, this invoice page will be located on a central site where it will be accessed, filled, printed and saved/submitted from. I then will need to have that unique id field locked once the invoice is being saved/submitted and duplicated to the accounting department so that the unique id cannot be changed. Please i will greatly appreciate any support on this. Thank you.
