Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);}