Copy link to clipboard
Copied
I need to create a field that stores a document ID number, and changes everytime I click a "Save to Pdf button". For example to start the code I need an "ID1". At the end of the form I press the button I want the document to be saved and change to "ID2" . I don't want this numbers to repeat.
OK. In that case create a (read-only) text field (let's say it's called "ID") and add the following code to the Mouse Up event of your "Save to PDF" button:
this.getField("ID").value = Number(this.getField("ID").valueAsString)+1;
Copy link to clipboard
Copied
Is there only going to be one copy of this form, anywhere? If not, how will you prevent the copy from having the same ID as the original?
Copy link to clipboard
Copied
It is only one copy for each user, stored inside their computer.
Copy link to clipboard
Copied
OK. In that case create a (read-only) text field (let's say it's called "ID") and add the following code to the Mouse Up event of your "Save to PDF" button:
this.getField("ID").value = Number(this.getField("ID").valueAsString)+1;
Copy link to clipboard
Copied
is there a chance to Save the document in the same button, besides saving to pdf, so I can assure that the ID number never repeats, when the document is reopened.
Copy link to clipboard
Copied
I would simply place the code as the document's Will Save event, under Tools - JavaScript - Set Document Actions.
Be aware this absolutely does not guarantee that. It's enough that someone goes back to an earlier version of the file for you to get duplicate IDs. If you want to ensure the IDs are unique either use random ones, instead of sequential, or assign them in a single location (for example, on your computer, after they are submitted back to you).
Copy link to clipboard
Copied
is there a chance to set the ID field as the name of the document saved by user. For example the id says "ID1" and when the document is ready to save it'll appear the as "ID1.pdf"
Copy link to clipboard
Copied
No. You can't force the file to be saved under a specific name.