Back Forward More about function rules

About Function rules

 zzz Show all 

 zzz Where functions can be called

Functions can be called within expressions and in Java code. The syntax differs slightly.

 zzz Deleting all functions in a library

You can delete a function rule with the Delete (Delete) toolbar button or (if checked out to you) the Delete Checkout (Delete checkout) toolbar button.

When you delete a function rule, Process Commander does not check to see whether the function is referenced in other rules (such as expressions or alias function rules). If the function may be called somewhere, open the Library form for the library to which this function rule belongs and click  Generate Library   to force recompilation of the library. At runtime, any references to the deleted function fail.

When you delete a library rule with the Delete (Delete) toolbar button, the system also deletes all function rules in the library (for all RuleSet Versions for the RuleSet), and deletes the assembled and Java-compiled functions in the library. In a multinode cluster, if you delete a library rule, the system pulse processing performed by the Pega-RULES agent on other nodes deletes the compiled Java and CLASS files from disk. .

 zzz Syntax for calling functions

To call a function as part of an expression, use syntax similar to:

@(Pega-RULES:DateTime).getCurrentTimeStamp();

where Pega-RULES is the name of the RuleSet and DateTime is the name of the library.

Some functions accept parameters. Usually, when you call a function from within an activity, refer to the activity using Java's this keyword.

@(Pega-RULES:Default).GetInstanceHandle("pageName", this);

Calling functions from Java

zzzYou can incorporate custom Java in any of six rules:

Functions when compiled extend the Java class:

com.pegarules.generated.myruleset_mylibrary

where the RuleSet name and library name are converted to lowercase. To call a function from within Java, use the following syntax:

result =
com.pegarules.generated.myruleset_mylibrary.MyFunction( params )

using the exact case for the function name.

Calling functions with side effects

To call a function primarily for its side effects (rather than to return a value), you can use the Property-Set method and place the result in a local variable. (Make sure the function returns a non-void value, such as a Boolean).

On the left-hand side (destination) of the Property-Set, enter Local.myLocalBoolean. On the right-hand side, use the call syntax above.

 zzz Using function alias rules to simplify decision rules

If your application includes decision table, decision tree, map value, constraints, or Declare Expression rules that are to be maintained by users or less technical staff, you can define function alias rules to simplify their work and present choices in application-centric terms. See About Function Alias rules.

 zzz How functions appear in generated Java

In the generated Java, function calls look like:

pega_rules_default.getCurrentTimeStamp();

 zzz How to recompile all libraries at once

When necessary, you can force extraction and recompilation of all functions in all libraries (on the current node):

  1. Stop the application server.
  2. Delete the text file PegaRULES_Extract_Marker.txt file.
  3. Restart the application server.

This adds an INFO line to the Pega log noting the re-extraction.

 zzz Advanced note: helper methods

Advanced featureYour Java code can contain helper methods that support the function rule computations. Define an inner class and define all the helper methods inside it. From the Java code outside this class you can create an instance of this class and can access the methods of this class. The inner class methods are not exposed.

For an example, review the Java tab of the standard edit input rule named PartialDate.

 zzz Advanced note: Function overloading

Advanced featureYou can define two or more function rules in one library with the same name, RuleSet, and version if the signatures are different. When Java code (or an expression) includes a call to the function, Process Commander uses the number, position, and data types of function parameters to determine which rule to execute.

The signature consists of the function name plus the types and names of the parameters in order.

 zzz Advanced note: Attributes of parameters

Advanced featureEach parameter of a function rule contains the following additional attributes. These are available for documentation purposes only; they do not affect Java code generation or other processing.

 zzz Advanced note: Return values

zzzThe return value of a function contains the following additional attributes:

 zzz Advanced note: Other properties of function rules

zzzFunction rules contain attributes and capabilities including:

 zzz Advanced note:J2EE enterprise support

Advanced TipWhen executing in the enterprise tier of a J2EE application server, applications cannot directly read from or write to the server file system. To minimize maintenance issues with custom Java code you write that may run in J2EE enterprise mode, do not use native java.io routines. Instead, use the Virtual File Interface (part of the Public API), which provides similar methods with the same names.
For Web tier installations, the Virtual File Interface methods merely call the corresponding native Java methods.

Definitions Virtual File Interface
Related topics About Library rules
Using Java in activity steps
How to set up a Java development environment
Standard rules Atlas — Standard functions

zzzAbout Function rules