Validating the Syntax and Correctness of Your Script

To validate the syntax and correctness of any script you write, click on the Validate script button in the expression editor toolbar as shown in the figure below.


Validating the Syntax and Correctness of Your Script

The validator highlights places in your script where you've violated the rules of Groovy scripting language syntax, making them easier to find and correct. For example, this helps you catch mismatched parenthesis or curly braces. The process also checks for the most common kinds of typographical errors like when you misspel the name of a built-in, global, or object function, or when you mistype the name of a field. Wherever your script calls a function, the system ensures that you have passed the correct number and types of arguments and that the security policy allows using that function.

The figure below shows the result of validating a script that contains three typographical errors. In line 2, the computeDefaultDueDate() function name is incorrect because the actual function name is calculateDefaultDueDate(). In line 3, the local variable defaultDueDate is misspelled as defaultDoDate. In line 4, the name of the field passed as the first argument to the setAttribute() function is incorrect, because the actual field name is DueDate_c. A fourth warning message appears related to the plus sign (+) operator. Since the defaultDoDate is not recognized, the validator assumes it must have the default type Object which does not have a function named plus(). To quickly navigate to the line containing an error or warning, just click on the relevant line in the Messages panel. The cursor moves automatically to the line and column containing the problem in the expression editor.


Example of Script Validation Errors and Warnings