Back Forward Functions in expressions

  Show all 

need to update this to include references to SQL Functions wetma

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.

NoteB-1957 Use the keyword <current> as a function argument to substitute the current value of the target property in an expression.

  How to call function rules

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.

Preferred call syntax

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

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

Short form call

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:

  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 Process Commander 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 still exists in the list, report an error.

Calling functions within a Java step

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.

  Built-in and When() functions

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)

Advanced featureThe 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 ClipboardPage PublicAPI object (not a page name) as the primary page for evaluation. Either parameter can be an expression that evaluates to the correct data type.

NoteThe primary page for evaluation is supplied as a ClipboardPage object, not a page name, so that embedded pages (or pages whose name is not known) can be evaluated.

You can use a Value List, Value Group, or Page Group property as an argument to the @SUM(), @MIN(), @MAX() and @AVERAGE().

  Arithmetic functions

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

  Date and time functions

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 BigDecimal value (Process Commander Date) corresponding to the int parameters specified. The year is a four digit year, and is not adjusted for a “base date.” The parameters are interpreted leniently (as in Excel) through the use of the Java Calendar class.

@datevalue(string)

Returns a BigDecimal value (Process Commander Date) corresponding to the parsed value of the string specified. Only the date portion of the string is considered.

@day(double) @day(BigDecimal))

Returns the int value corresponding to the day of the month (1 to 31) when the double parameter is interpreted as a Process Commander Date.

@month(double)
@month(BigDecimal)

Returns the Java int value corresponding to the month of the year (0 to 11) when the double parameter is interpreted as a Process Commander Date. The corresponding Excel function also returns 0 to 11.

@today()
@today(selection)

Returns the BigDecimal value (Process Commander Date) corresponding to the current date.

@weekday(double)

@weekday(BigDecimal)

Returns the int value corresponding to the day of the week (Sunday = 1 to Saturday = 7) when the double parameter is interpreted as a Process Commander Date.

@year(double)

@year(BigDecimal)

Returns the int value corresponding to the year when the double parameter is interpreted as a Process Commander Date.

@hour(double)

@hour(BigDecimal)

Returns the Java int value corresponding to the hour of the day (0 to 23) when the double parameter is interpreted as a Process Commander Time of Day.

@minute(double)

@minute(BigDecimal)

Returns the Java int value corresponding to the minute of the hour (0 to 59) when the double parameter is interpreted as a Process Commander Time of Day.

@second(double)

@second(BigDecimal)

Returns the Java int value corresponding to the second of the minute (0 to 59) when the double parameter is interpreted as a Process Commander Time of Day.

@time(hour, minute, second)

Returns a BigDecimal value (Process Commander Time of Day) corresponding to the int parameters specified.

@timevalue(string)

Returns a BigDecimal value (a Process Commander Time of Day value) corresponding to the parsed value of the string specified. Only the time portion of the string is considered.

The following functions facilitate conversion between BigDecimal/double values derived from DateTime properties and Date or Time of Day properties, the following functions are provided.

Use these functions to adjust the double value resulting from the sum of a Date and Time of Day or the double value resulting from a DateTime property into a (possibly different) known time zone. The return type of these functions is the same as the type of the first argument.

@toGMT(double, zone)

@toGMT(BigDecimal, zone)

Returns a double/BigDecimal value (Process Commander DateTime) in the GMT time zone corresponding to the double value interpreted in the “zone” time zone. Use to convert the sum of a Date and Time of Day to a DateTime. If zone is null, then the time zone of the requestor is used.

@toLOCAL(double, zone) NOT WORKING 11/17/06 OLSOK

@toLOCAL(BigDecimal, zone)

Returns a double/BigDecimal value that is the result of treating the double value as a Process Commander DateTime” (in the GMT time zone) and converting it to the time zone. You can then treat the resulting value as Date and Time of Day values in the specified time zone. If zone is null, then the time zone of the requestor session is used.

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

Advanced featureThe 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.

Up About expressions