Copy link to clipboard
Copied
I have a document javascript that autoincreases a quote number on a form each time the document is opened. The user opens the form, fills it out and completes the form (with a button that makes all form fields read-only) and then saves the form as a new document name to their desktop. The problem is if they then re-open the completed form the quote number still changes. When the quote is sent to a customer and they open it, the quote number changes and then we aren't able to track the quote because the customer may refer to one quote number that they get when they open a form but that's not the quote number that was originally on the form and saved in the system. I need a way to make this javascript stop running when the document is saved or something so the quote number stays the same each time its opened AFTER its been completed and saved. Any ideas? Here is the javascript i'm using to auto-generate a quote number each time the form is opened.
this.getField("Quote Number").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Thanks!
Use this:
if (this.getField("Quote Number").value == "")
this.getField("Quote Number").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Copy link to clipboard
Copied
Set the value of the field when the field is empty.
Copy link to clipboard
Copied
Since your button locks all fields it can also remove the script.
JavaScript don't allow to remove a document script, but you can use the "addScript" method to overwrite the existing one and replace it by a double-slash or by nothing at all.
Copy link to clipboard
Copied
That won't work in Reader, though.
Copy link to clipboard
Copied
Ok any ideas on what i could do then? Because the users that will be using the form will be using reader.
Copy link to clipboard
Copied
Use this:
if (this.getField("Quote Number").value == "")
this.getField("Quote Number").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Copy link to clipboard
Copied
Hi,
Can you tell me how to use this script, but change it to produce a sequential number please.
Ms. V
Copy link to clipboard
Copied
That won't work in Reader
Yes. I forgot this "small detail" 😉
Copy link to clipboard
Copied
I tried that and it works when you complete the form but it doesn't autog-generate a new quote number when the form is first opened before it's completed. Is that because the field isn't empty?
Copy link to clipboard
Copied
Sorry i forgot to say @Bernd with my comment above.
Copy link to clipboard
Copied
Clear the field before you save the form.
Copy link to clipboard
Copied
THANK YOU!! THAT WORKED!