You are here: Record management > Building expressions with the Expression Builder > Functions in expressions > Methods for calling a function

Methods for calling a function

The following forms call a function:

Fully qualified function call

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).

Library qualified function call

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.

Unqualified function call

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:

  1. Collect a list of the Rule-Utility-Function rules belonging to the rulesets listed in the user's ruleset list that have the same name and same number of parameters.
  2. Exclude functions defined in any library named default. (The use of the default library is deprecated.)
  3. If the list is empty, no such functions exist. The system reports an error.
  4. If more than one such function exists (because the same name is overloaded), select the best match by comparing the data types of the parameters, using the promotion rules for Pega Platform data types.
  5. If the Rule-Utility-Function rule has not supplied data types for its parameters or return value, use standard Java promotion rules to match parameters. As a last resort, substitute double for the preferred BigDecimal type if necessary to get a match.
  6. If more than one function matches the selected name and fully decorated signature, then the function from the higher listed ruleset is executed.

Java call

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.