Skip to main content
Participant
May 22, 2023
Answered

Disabling Javascript in new file when Save As is used

  • May 22, 2023
  • 1 reply
  • 1602 views

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.

This topic has been closed for replies.
Correct answer try67

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));
}

1 reply

try67
Community Expert
Community Expert
May 22, 2023

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?

Participant
May 22, 2023

That would I do believe work perfectly!

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 22, 2023

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));
}