Resolving Groovy Business Rule Validation Issues
As you migrate to an upgraded version of Groovy, you may encounter certain issues that need to be addressed. A program called the Groovy Script Validator aids in finding the rules that need to be adjusted and provides a report so you can fix any issues.
The Groovy Script Validator is only available only when your application contains user-created Groovy business rules. See Validating Groovy Scripts for information on how to run the Groovy Script Validator.
After you run the Groovy Script Validator, use the information in this topic to resolve validation issues.
General Guidelines
-
The first row of all Groovy scripts should contain a comment to hold the RTPS, even if the script contains no RTPS. For example, the first row should look like this if the rule contains no RTPS:
/* RTPS: */
, and like this if the rule has a RTP named "CopyTo":/* RTPS: {CopyTo}*/
. -
In Rules, instead of the curly brackets notation like
{scenario}
, use the new Groovy model:rtps.scenario
. -
In Templates, instead of using square brackets like
[scenario]
, use the new Groovy model:rtps.scenario
. -
Use Explicit Data Types instead of using
def
. For example, specify the explicit data type for variables, such asString
,int
, orList.
-
When defining Generic Lists and Maps, specify the type, such as
List<String>
orMap<String, Integer>
. -
When working with floating numbers, use the "d" suffix to ensure the floating numbers are treated as "double" instead of "BigDecimal". For example,
it.data = 1212121212.111d
. -
Replace deprecated Date functions with corresponding Calendar functions.
Errors and Suggested Fixes
Table 3-2 Errors and Suggested Fixes
Error | Example Code | Possible Cause | Possible Solution |
---|---|---|---|
No such property: |
N/A |
This may be the result of not using the RTPS model, and the variables are referenced via square brackets or curly braces. This results in the Groovy engine trying to evaluate them as Groovy expressions. |
Use the |
Cannot assign value of type |
|
The error occurs because the List data is not explicitly typed, so
Groovy treats it as a |
To resolve this issue, do one of the following:
|
Cannot assign value of type |
|
The error occurs because the object being assigned is not explicitly
typed or cast to an |
To resolve this issue, cast the value to Use the as For example:
|
Cannot assign value of type |
|
The error occurs because |
To resolve this issue, add the For example:
|
Cannot call the following:
|
|
The error occurs because |
To resolve this issue, specify the data type of the variable. For example:
|
Cannot call the following:
with arguments
|
|
The error occurs because |
To resolve this issue, add the For example:
|
Cannot find matching method
|
|
The error occurs because the |
To resolve this issue, enter the following:
|
Cannot find matching method
|
|
The error occurs because the format method, which was previously available in earlier versions of Groovy, is no longer available. |
To resolve this issue, enter the following:
|