Copy link to clipboard
Copied
The code shows as below:
app.alert(1);
app.alert(this.getField("IsModified").value);
app.alert(2);
I put the script in document level. When I finish editing the script, it gives me 3 popup as expected.
After I closed the PDF and reopen it, it gives me the first popup ONLY.
I checked the debugger. It gave me the error as below:
TypeError: this.getField(...) is null
3:Document-Level:alertTest
I can tell the problem is on this.getField("IsModified"). But why this happens? And how should I fix it?
Copy link to clipboard
Copied
It essentially means that a field named "IsModified" does not exist.
Carefully check spelling. Maybe locate the field, open its properties dialog, and copy the field name from there, and paste it into the code.
Hope this can help.
Copy link to clipboard
Copied
As a test, what happens if you place the same code in a button and click the button?
Copy link to clipboard
Copied
How (and where) did you create the field?
Copy link to clipboard
Copied
Try the following script:
app.alert(1);
var oField = this.getField("IsModified"); // get field object;
// see if there was an error accessing the field object;
if(oField == null) {
app.alert({cMsg: "Error accessing field \"IsModified\".\nPlease check field name, spelling, and capitialization.",
nIcon: 1,
nType: 0,
cTitle: "Field Error Condition"
});
} else {
app.alert(this.getField("IsModified").value);
}
app.alert(2);
This script check the return value for the getField method and issues an alert if there was a problem accessing the provided field name. Check to make sure the field really exist.
I add a document level function that I use in place of the this.getField method which includes the check of the return value for the this.getFeild method.
Copy link to clipboard
Copied
Hello,
I am running into what appears to be the same problem. I have this document level script that returns "null" when I perform a getField when I first open the document. If however I interact with another part of the document OR I put it in "Prepare Form" mode in Acrobat DC and then back into preview, it works just fine. So I know the field name is correctly spelled.
It almost appears as if the field object doesn't get created upon document launch, but that something triggers the field creation later.
Any thoughts? Did you resolve this issue?
Cheers
Copy link to clipboard
Copied
To have a field object you need an open PDF form. Do you have an open form at the yime the script is running?
Copy link to clipboard
Copied
Did you happen to create the form in InDesign, or some other application (ie, not in Acrobat)?
Copy link to clipboard
Copied
Hello,
Thanks for the reply. I believe it was created in InDesign. I was just making the form "actionable".
Cheers
Copy link to clipboard
Copied
I've encountered similar issues with form fields that were created in InDesign, which is why I always recommend to only create fields in Acrobat, not in any other application.
This is really a bug that Adobe should solve...
Copy link to clipboard
Copied
Thanks. Seems like that might be the most effective way to get past this. I'll just recreate the fields in acrobat.
Copy link to clipboard
Copied
Thanks again, I just wanted to confirm that recreating the fields in Acrobat has resolved the issue. I've tested it and those InDesign fields that I have not yet replaced still suffer from the problem, whereas the Acrobat created ones work as expected.