Functions in expressions |
Functions extend the power of Process Commander expressions. An expression can contain calls to built-in functions, standard functions, and custom functions you create.
Use the Function Builder to help you find the function you need. An expression can contain many function calls, including nested calls.
B-1957 Use the keyword
<current>
as a function argument to substitute the
current value of the target property in an expression.
This article relates to creating and using Java functions. For information about creating and using SQL functions in Report Definition rules, see About Report Definition Rules and Report Definition Rules - Using the Function Builder.
Use these three forms to call a function — a preferred version that explicitly identifies the library and RuleSet, a short form that may be useful in special situations, and a third form used only within Java.
The full syntax for calling a function identifies both the RuleSet and the library:
@(RuleSet:libraryname).functionname(arg1, arg2... argn)
For example:
@(MyInventory:Sort).CardType("Gold")
An alternative deprecated syntax, used before Version 04-01, is still available:
lib(RuleSet:libraryname).functionname(arg1, arg2... argn)
where RuleSet may be omitted (defaults to Pega-RULES
),
and library may be omitted (defaults to default
).
You can use this notation to call a function rule:
@FunctionName(arg1, arg2... argn)
This syntax does not identify a RuleSet or a library for the function. Your system may contain many functions that match the function name. Process Commander 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: B-18409 exact case SDAS 3/21/06
myinventory_sort.CardType("Gold")
Process Commander 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.
Four functions are part of the expression language. All other names following an at-sign are references to function rules, instances of the Rule-Utility-Function rule type. An expression can use any of these built-in functions:
Syntax |
Description |
These functions are part of the expression language. Their names are reserved and cannot be overridden. These functions may only be invoked using the preferred (‘@’) syntax. |
|
@if( boolean expression, result1, result2) |
Evaluates the condition in parameter one and then, if true, evaluates and returns parameter two, otherwise evaluates and returns parameter three. Equivalent to the Java ternary operator “?:.” Only the one appropriate result parameter is evaluated. |
@and( e1, e2, ...) |
Logical AND operation of the (arbitrary number of) parameters (Evaluated left-to-right, stopping when the result is known) |
@or( e1, e2, ...) |
Logical OR operation of the (arbitrary number of) parameters (Evaluated left-to-right, stopping when the result is known) |
@java( code) |
The single parameter is treated as Java code and inserted into the translated Java stream without examination or modification. |
General purpose | |
@when(name) |
Evaluates a when condition rule in the context of the primary page of the rule in which the expression appears. The parameter can be an expression that evaluates to a text value. |
@when(name, pagename) |
Evaluates the specified when condition rule using the
supplied
The
primary page for evaluation is supplied as a
|
You can use a Value List
, Value Group
, or
Page Group
property as an argument to the @SUM(),
@MIN(), @MAX() and @AVERAGE().
These basic arithmetic functions are available.
Syntax |
Description |
Scalar arithmetic | |
@abs(num) |
Absolute value |
@sqr(num) |
Square |
@sqrt(num) |
Square root |
@exp(num) |
Exponential |
@ceil(num) |
Ceiling, least integer not greater than |
@floor(num) |
Floor, greatest integer not less than |
@round(num) |
Rounded to the nearest integer |
Aggregate arithmetic | |
@sum(num1, num2) |
Sum |
@max(num1, num2) |
Maximum |
@min(num1, num2) |
Minimum |
@mode(num1, num2) |
Modal value Documentation is in progress RETRACTED? |
@stddev(num1, num2) |
Standard deviation Documentation is in progress RETRACTED? |
@average(num1, num2) |
Average |
You can use a Value List
, Value Group
, or
Page Group
property as an argument to the @SUM(),
@MIN(), @MAX() and @AVERAGE().
The following functions operate with date and time values. A
DateTime
Type property represents an instant in time
while Date
and TimeofDay
Types represent
values. Adding (the BigDecimal/double values corresponding to) a
Date
and a TimeofDay
together similarly
represents an instant in time, but in an unknown or arbitrary time
zone.
Syntax |
Description |
These Rule-Utility-Function rules are similar to the corresponding functions in Excel. |
|
@date(year, month, day) |
Returns a |
@datevalue(string) |
Returns a |
@day(double) @day(BigDecimal)) |
Returns the |
@month(double) |
Returns the Java |
@today() |
Returns the |
@weekday(double) @weekday(BigDecimal) |
Returns the |
@year(double) @year(BigDecimal) |
Returns the |
@hour(double) @hour(BigDecimal) |
Returns the Java |
@minute(double) @minute(BigDecimal) |
Returns the Java |
@second(double) @second(BigDecimal) |
Returns the Java |
@time(hour, minute, second) |
Returns a |
@timevalue(string) |
Returns a |
The following functions facilitate conversion between
BigDecimal/double values derived from Use these functions to adjust the double value resulting
from the sum of a |
|
@toGMT(double, zone) @toGMT(BigDecimal, zone) |
Returns a double/BigDecimal value (Process Commander
|
@toLOCAL(double, zone) NOT WORKING 11/17/06 OLSOK @toLOCAL(BigDecimal, zone) |
Returns a double/ For example, if bostonTime is a double that represents a date and time in the Eastern Standard Time zone, you can find the corresponding time in India by using: toLOCAL(toGMT(bostonTime, “EST”), “IST”) |
Calling an activity in an expression
The standard function callActivity( ) in the Pega-RULES Utilities library calls an activity, but returns only void, not a value result. You can execute an activity in an expression, but only for its side effects. MARIK 2/9/07 clinic. Identify the primary page, the activity, and the parameter page. For example:
@Pega-RULES:Utilities.callActivity(pyWorkPage,
MyActivity,
tools.getParameterPage());
Calling an overloaded function
Process Commander allows multiple function rules to be defined with the same name, in the same RuleSet, version, and library, if they have different signatures. The signature of a function is computed automatically from the name, the position and data types of parameters, and the return type. Functions that have multiple variants are called overloaded.
When calling an overloaded function, you do not need to specify which variant to use. The system determines which to use based on the types and positions of parameters you supply.
For example, assume one function named Round is defined with two variants:
If your call includes two parameters, the system uses the second variant.