Copy link to clipboard
Copied
I have a PDF form that I put together that has a document number at the top. I have a javascript in the document to increment that number up by 1 every time the form is opened:
var v = +this.getField("Permit Number").valueAsString+3000;
this.getField("Permit Number").value = util.printf("%04d", (v+1-3000));
I know very little javascript and I found this example somewhere online and modified it for my own needs.
Is there a way so that when this form is filled out and Save As is used to save the filled out form that the javascript is disabled in the new file? I don't want the document number to change again if someone opens the filled out form later on.
Copy link to clipboard
Copied
You can use something like this, then (adjust the actual file name in the first line, of course):
if (this.documentFileName=="OriginalName.pdf") {
var v = +this.getField("Permit Number").valueAsString+3000;
this.getField("Permit Number").value = util.printf("%04d", (v+1-3000));
}
Copy link to clipboard
Copied
You can modify the code so that it only updates if the file has a specific file name (and not others). Would that work for you?
Copy link to clipboard
Copied
That would I do believe work perfectly!
Copy link to clipboard
Copied
You can use something like this, then (adjust the actual file name in the first line, of course):
if (this.documentFileName=="OriginalName.pdf") {
var v = +this.getField("Permit Number").valueAsString+3000;
this.getField("Permit Number").value = util.printf("%04d", (v+1-3000));
}
Copy link to clipboard
Copied
That works great! Thank you!
Now a follow up question which may be a little more tricky:
I'm now trying to add to the script to have it save the file immediately after opening and having the new number plugged in so it's ready for the next time being opened (especially after the form is filled out and it's "saved as" a different file name). Trying to use app.execMenuItem("Save"); doesn't work which seems to be due to security concerns; doing a lot of searching on the web to make this function has not gotten me very far. Thoughts?
Copy link to clipboard
Copied
In order to do that you must install a script file on the local machine of each user who will use this file. Can you do that? If not, the closest you can get is to open the Save As dialog. Just change "Save" to "SaveAs" in your code.
Copy link to clipboard
Copied
Unfortunately no; they are managed machines here and we have no installation or admin access of any kind. The SaveAs should work well enough though as a reminder for them to save it before editing.
Thank you very much for all your help!

