You are here: Reference > Rule types > Function rules > More about Function rules

More about function rules

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

Where functions can be called

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

Deleting all functions in a library

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

When you delete a function rule, Pega 7 Platform 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.

Calling functions from Java

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

See Functions in expressions for more information on calling a function within a Java step of an activity.

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 ruleset contain utility function rules, run the Rule Security Analyzer before locking a ruleset version, to look for possible security issues.

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.

Advanced note: helper methods

Your 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 note: Function overloading

You 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, Pega 7 Platform 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 note: Attributes of parameters

Each 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 note: Return values

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

Advanced note: Other properties of function rules

Function rules contain attributes and capabilities including:

Advanced note: Java EE support

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

About Function rules