Back Forward More about function rules
 

  1. About 
  2. New 
  3. Parameters 
  4. Java 
  5. Alias 
  6. Imports & Exceptions 
  1. History 
  2. More... 

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

You can delete a function rule with Delete or (if checked out to you) Discard.

When you delete a function rule, PRPC 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 Delete, 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. PROJ-338 SDAS 2/27/07.

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

Advanced featureYou can incorporate custom Java in rules of these six rule types:

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.

Security

If your application rulesets contain utility function rules, run the Rule Security Analyzer before locking a ruleset version, to look for possible security issues.

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.

In the generated Java, function calls look like:

pega_rules_default.getCurrentTimeStamp();

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.

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.

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, PRPC 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.

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.

Advanced featureThe return value of a function contains the following additional attributes:

Advanced featureFunction rules contain attributes and capabilities including:

TipWhen executing in the enterprise tier of a Java EE 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 Java EE 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

UpAbout Function rules