The following forms call a function:
The fully qualified syntax for calling a function identifies both the ruleset and the library:
@(RuleSet:libraryname).functionname(arg1, arg2... argn)
For example:
@(MyInventory:Sort).CardType("Gold")
Using fully qualified references eliminates the risk of function overrides by a library or ruleset.
By fully qualifying a ruleset, standard ruleset resolution does not apply. Double-check your requirements before using this type of function call.
Note: A deprecated syntax used before Version 04-01 is still available as an alternative to using a fully qualified function call:
lib(ruleset:libraryname).functionname(arg1, arg2... argn)
When using this syntax, "ruleset" may be omitted (defaults to Pega-RULES
), and "libraryname" may be omitted (defaults to default
).
The library qualified syntax for calling a function identifies the library name:
@LibraryName.FunctionName(arg1, arg2... argn)
Using library qualified references provides a more readable syntax than the fully qualified syntax, and prevents accidental library conflicts that can occur with unqualified calls.
For example, if two libraries with the same name are located in different rulesets, when using library qualified notation, the library from the ruleset listed higher in the operator runtime ruleset list is selected.
Additionally, using this notation helps to avoid multiple "suitable found" instances, such as when the same function exists in two different libraries but in the same ruleset.
With library qualified references, standard ruleset resolution applies, allowing the function to be resolved from any ruleset. This provides the capability to override a function in a different ruleset name, similar to how other rule types can be overridden.
The unqualified syntax for calling a function calls a function rule:
@FunctionName(arg1, arg2... argn)
The unqualified syntax is the simplest to read, but does not identify a ruleset or a library for the function. Your system may contain many functions that match the function name.
Note: When using this syntax, if another developer creates a function with the same name and signature in another library or ruleset, their call may be affected.
Pega Platform uses your ruleset list to find the best one to execute, using the following algorithm:
double
for the preferred BigDecimal
type if necessary to get a match.To call in a function within a Java step of an activity, use standard Java conventions. Concatenate the ruleset name with an underscore and the library name, converting all letters to lowercase and characters other than digits and letters to underscores.
For example, to call the CardType() function in the Sort library of the MyInventory ruleset, use:
myinventory_sort.CardType("Gold")
Pega Platform constructs the Java class name for a Rule-Utility-Library by concatenating the ruleset name, an underscore and the library name, with the resulting string converted to lowercase and characters not valid in a Java identifier translated to an underscore.