Skip to main content
Known Participant
February 28, 2020
Question

How do I make a form that generates a unique number when the form is saved?

  • February 28, 2020
  • 3 replies
  • 7798 views

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.

This topic has been closed for replies.

3 replies

JR Boulay
Community Expert
February 29, 2020

Any PDF file already generates and have a unique number when is saved, you just have to use it.

It's the Document ID: https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/Acro12_MasterBook/JS_API_AcroJS/Doc_properties.htm?rhhlterm=docid&rhsyns=%20#XREF_34893_docID

 

 

Try this in the JavaScript Console:

console.println(this.docID);

 

It will return something like:

20FAAAA0A98BC53D18538BFFC988A91C,E214604BE4C7494E9D18577786800EBD

Acrobate du PDF, InDesigner et Photoshopographe
Known Participant
March 1, 2020

Hi, JR_Boulay, thank you for the response, i so much appreciate it, please where and how do i enter the script? Thanks.

JR Boulay
Community Expert
March 1, 2020

In the JavaScript Console: https://acrobatusers.com/tutorials/javascript_console/

 

Or you can use this in a form field:

this.getField("FIELD").value = this.docID;

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
February 28, 2020

If you want to assign a random number to the field instead of sequential one (due to the issues described by TSN), replace this line of code:

this.getField("mySequenceID").value ++ ;

With this:

this.getField("mySequenceID").value = Math.floor(Math.random()*10000000);

Known Participant
February 28, 2020

Ok try67, thanks a lot, i will check that out and give feedback.

Brainiac
February 28, 2020

This is actually one of the most difficult things that beginners with forms want to do. The script you've found is more or less OK when one person is using it, but it just won't cut it for you, and there may not be a good alternative. The problem is, 

- each invoice is going to need to be saved somewhere different

- the master invoice needs to be saved to the same place every time but only with the updated invoice number.

Frankly, asking a team of people to remember to do this isn't going to fly. Because this is so hard, and because you are entering a really complicated world of workgroup sharing, I recommend you forget PDF forms and forget the idea of do-it-yourself. This needs a tried and tested professional solution, running on a server, with a database, locking, synchronization, auditing, reports, and offload to your accounting system. In fact, if you have an accounting system it may do this already. Believe me, nothing goes more badly wrong more quickly than a solution made for one person, then scaled up to a even a small team.

Known Participant
February 28, 2020

Hi, Test, thank you for your recommendation, however, i have updated the question, here is it.

 

If the invoice can 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 now only be located on a central site where it can be accessed, filled, printed and saved/submitted from, but it will not longer require to be downloaded, or accessed from multiple locations. 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. Test_Seen_Name