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.
Note:
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 from your application, use the information in this topic to resolve validation issues.
General Guidelines
-
Use Explicit Data Types instead of using
def
. For example, specify the explicit data type for variables, such asString
,int
,List<String>
, orMap<String,Integer>
.Note: If you are using
def
and it is not being flagged by the validation tool, you can leave it as is. -
If you get an error 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
. -
If you get an error that you do not understand, verify that the first line of the script looks like this:
/*RTPS: */
Even if you have no RTPs, make sure this is the first line.
If you have RTPs, add them to the first line like this:
/*RTPS: {selectedDepartment} {hireDate} {newEmployeeName} */
.
Note:
You are no longer required to replace deprecated Date functions with corresponding Calendar functions as part of the validation process. This has been resolved and is no longer an issue. The Date.format(), Date.getAt(), Date.parse() etc. methods now work and no longer show validation errors.
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:
|
Cannot find matching method
o |
List <Cube> cube = operation.application.getCubes()
Dimension dimScenario =
operation.application.getDimension("Scenario", cube.toArray(new
Cube[cube.size()])) |
A |
Ensure the declared type is correct and he method exists. If only a dimension valid for a particular cube is needed, enter the following:
|