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, 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.
You can incorporate custom Java in rules of these six rule types:
Java
directive, and other stream-based rules (XML, correspondence, HTML fragments, correspondence fragments, harness, sections, and flow actions)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.
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.
If your application ruleset 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.
When necessary, you can force extraction and recompilation of all functions in all libraries (on the current node):
PegaRULES_Extract_Marker.txt
file.This adds an INFO line to the Pega 7 Platform log noting the re-extraction.
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.
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.
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.
pyUsage
, a description of what the parameter is and how it is used (for JavaDocs)pyDataType
, available to document the Pega 7 Platform data type of the parameter if the corresponding Java data type is String
or ClipboardProperty
pyPageClass
, if pyDataType
is Page
, can document the class (or superclass) of the pagepyMode
, can document whether the parameter is an input or output value.The return value of a function contains the following additional attributes:
pyUsage
, a description of the return value (for documentation such as JavaDocs)pyDataType
, the Pega 7 Platform data type of the return value if the Java data type is String
or ClipboardProperty
pyPageClass
, if pyType
is Page
, optionally identifies the class (or superclass) of the page pyIntrinsic
, reserved for future use to support efficient inline code generation. Function rules contain attributes and capabilities including:
pyImports
, a list of packages to be imported into the library.pyThrows
, a list of Java exceptions thrown by the function.pyInline
, a hint to Java translators of when this function can be included within a rules assembly class: Never
, Always
, If appropriate
.pyIntrinsic
, a hint to Java translators that if the translator has its own optimized implementation of a function with the same name, it may use that version: true
or false
.pyMethodFrom
, reserved for future use. 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.