Groovy Rule

A groovy rule runs a snippet of groovy code that returns true if error messages should be displayed in PDX UI.

The groovy rule builder has the following additional properties:

METHOD(s)DESCRIPTION
.withGroovyCode(String snippet)
.withGroovyCode(File groovyFile)
.withGroovyLines(List<String> lines)
  1. String containing a groovy snippet to be parsed into rule
  2. File object that refers to a rule.groovy file to be parsed into rule
  3. Lines from a groovy code to be parsed into rule
Regarding parsing, see note below table.
.withAlias(String alias, String attributeId)A valid groovy variable name that is used in the groovy snippet to refer to the value of the attribute with the given attribute ID
.withErrorAliases(String... aliases)A list of aliases for the attributes that should display error message in PDX UI
.withErrorMessage(String errorMessage)The error message that will show up in PDX UI on the error attributes if groovy snippet returns true
📘

When groovy code is added via one of the three methods, it is automatically processed as follows:

code is compacted into a single line (remember to add semi-colons so that the code still compiles)

package and line containing predefined imports of BusinessRuleUtils and GroovyExecutionScope are removed

comment lines using // are removed

GroovyExecutionScope.SOME_FIELD is replaced by the internal groovy code, it represents, e.g. GroovyExecutionScope.CHANNEL_PRODUCT becomes context.get(“CHANNEL_PRODUCT”)

required contexts are automatically detected - see the JSON result under File based rule, where “CHANNEL_PRODUCT” was picked up


Did this page help you?