Copy link to clipboard
Copied
My quote generator code is currently set at document level (see below);
this.getField("quote_number").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
I would like to be able to save a copy of the form after it is filled out, but when I save the form now and reopen it, it generates a new quote number.
I believe this can be done using a global object, but I am not sure how to set that up.
Any advice is greatly appreciated!
Thank you in advance! 🙂
Copy link to clipboard
Copied
You need to clearly define when the number should change, and when it shouldn't.
For example, you can set it up so that it will only change if the field is empty.
Copy link to clipboard
Copied
Thank you, but I'm not sure I understand?
The field automatically generates a number, meaning it is never empty.
I would like the number to "stick" on save, so that a copy of the form can be saved.
Not sure how to write this, or where to put it in the PDF document.
Copy link to clipboard
Copied
So after the file is saved the field should never update again? In that case, you might as well set it to only populate when the field is empty, and then clear it (with JavaScript disabled), to achieve it.
To do that change your code to:
if (this.getField("quote_number").valueAsString=="")
this.getField("quote_number").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Copy link to clipboard
Copied
Thank you so much for your help! That works 🙂
Is there any way to have the template continue to generate a random number, then execute that script once the form has been filled out and saved?
Not sure if that makes sense...My client will be reusing the form, so they will need to generate a new quote number once the template is opened, then once they have filled it out for a customer, I would like them to be able to save that copy with the same quote number so they can refer back to it.
Is that possible?