Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
10

Debug Find causing field

Participant ,
Oct 02, 2023 Oct 02, 2023

Hey folks,

 

when working with different script in the calculation of some field values sometimes i get an error in the Console that looks like this:

TypeError: this.getField(...) is null
5:Field:Calculate

Is there any possibility to let the debugger post the complete script-line or at least the name of the caused field that was not able to found, like this:

TypeError: this.getField("my_field") is null
5:Field:my_field:Calculate

?

Thank you very much in advance

TOPICS
How to , JavaScript , PDF , PDF forms
867
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 02, 2023 Oct 02, 2023

Unfortunately, no. It used to work like that in earlier versions (like XI), but Adobe decided to change it to this useless error message format, for who knows what reasons, making the lives of developers that much more difficult.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 02, 2023 Oct 02, 2023

The exception object contains a "lineNumber" and a "fileName" property. So if all code is placed in a try/catch block,  the line number and source of the error can be printed. 

 

try{
   ... All Code ...
}catch(e){
    console.println(e.toString() + " - " + e.fileName + " : line# " + e.lineNumber);
}

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 02, 2023 Oct 02, 2023

Another option is to use an external tool to examine all the code in the file and look for missing field names.

It has some caveats, though. It only works if the field name is being supplied as a literal string, if you use something this.getField("Text"+i) in a loop, for example, it won't work.

I've developed such a tool, and it can also locate missing field names when using the built-in calculation options such as Sum, Average, etc., so it's pretty handy.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 02, 2023 Oct 02, 2023
LATEST

You can use this in your script, if any field name in your script have a name of non-existing field, console will print its name.

 

var fieldNames = ["Field1", "Text1", "Dropdown1"];//Put names of the fields you use in your script inside array.
var nullFields = [];

for (var i = 0; i < fieldNames.length; i++){
var fieldName = fieldNames[i];
var field = this.getField(fieldName);
if(field === null){
nullFields.push(fieldName);}}

if(nullFields.length > 0){
var message = "The following field/s name is not correct:\n" + nullFields.join("\n");
console.println(message);}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines