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 as String, int, or List.

  • When defining Generic Lists and Maps, specify the type, such as List<String> or Map<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: <groovy variable name> for class: groovy.lang.Binding

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 rtps.<variable name>, or recheck the expressions within the braces or brackets.

Cannot assign value of type type java.lang.Object to variable of type double

def data = []

double valFor = data[0]

The error occurs because the List data is not explicitly typed, so Groovy treats it as a List<Object>. When you access an element from the List using data[0], it returns an object, which cannot be directly assigned to a double variable.

To resolve this issue, do one of the following:

  • Explicitly type the list .

    Define the list with the correct type, such as List<Double>.

    For example:

    List<Double> data = []

    double valFor010 = data[0]

  • Cast the value to double.

    Use the as double syntax to explicitly cast the object to a double value.

    For example:

    def data = []

    double valFor010 = data[0] as double

Cannot assign value of type java.lang.Object to variable of type int

def finalList = mergeList.get(i)

int pmntfrequency = finalList.get(3)

The error occurs because the object being assigned is not explicitly typed or cast to an int. In this case, finalList.get(3) returns an object, which cannot be directly assigned to an int variable.

To resolve this issue, cast the value to int.

Use the as int syntax to explicitly cast the object to a int value or use the as int tag.

For example:

def finalList = mergeList.get(i)

int pmntfrequency = (int) finalList.get(3)

int pmntfrequency = finalList.get(3) as int

Cannot assign value of type java.util.List <java.lang.String> to variable of type java.lang.String[]

String[] arrGridMbrs = it.getMemberNames()

The error occurs because it.getMemberNames() returns a List<String>, which is not directly assignable to a String[] array.

To resolve this issue, add the as String[] cast to explicitly convert the List<String> to a String[] array.

For example:

String[] arrGridMbrs = it.getMemberNames() as String[]

Cannot call the following:

oracle.epm.api.grid.DataGridDefinitionBuilder#addPov(java.util.List <java.lang.String>, java.util.List <java.util.List>) with arguments [java.util.List <java.lang.Object>, java.util.List <java.lang.Object>]

def columnDims = []

def columnMbrs = []

builder.addColumn(columnDims, columnMbrs)

The error occurs because List<String> and List<List<String>> arguments are passed in as List<Object> and List<Object>.

To resolve this issue, specify the data type of the variable.

For example:

List<String> columnDims = []

List<List<String>> columnMbrs = []

builder.addColumn(columnDims, columnMbrs)

Cannot call the following:

oracle.epm.api.grid.DataGridDefinitionBuilder#addColumn(java.util.List <java.lang.String>, java.util.List <java.util.List>)

with arguments

[java.util.List <java.lang.Object>, java.util.List <java.lang.Object>]

dataGridDefinitionBuilder.addColumn(['Account', 'Period'], [['OCX_Payment Frequency'],['Begbalance']])

The error occurs because List<String> and List<List<String>> arguments are passed in as List<Object> and List<Object>.

To resolve this issue, add the as String[] cast to explicitly convert the List<String> to a String[] array

For example:

dataGridDefinitionBuilder.addColumn(['Account', 'Period'] as List<String>, [['OCX_Payment Frequency'],['Begbalance']] as List<List<String>>)

Cannot find matching method java.util.Date#getAt(int)

rtps.endDate.getDataAsDate().getAt(Calendar.YEAR)

The error occurs because the getAt(int) method, which was previously available in earlier versions of Groovy, is no longer available.

To resolve this issue, enter the following:

Calendar calendar = Calendar.getInstance()

calendar.setTime(rtps.endDate.getDataAsDate())

int year = calendar.get(Calendar.YEAR)

Cannot find matching method java.util.Date#format(java.lang.String)

rtps.endDate.getDataAsDate().format("yyyy-MM-dd")

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:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd")

String formattedDate = sdf.format(rtps.endDate.getDataAsDate())