Show all
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 the Delete () toolbar button or (if checked out to you) the
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 () 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.
PROJ-338 SDAS 2/27/07.
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
You can incorporate custom Java in any of
six rules:
- Activities, by using the Java instruction or the Property-Set
method
- Models
- HTML rules, using the
Java
directive, and other
stream-based rules (XML, correspondence, HTML fragments,
correspondence fragments, harness, sections, and flow actions)
- Edit Input rules
- Edit Validate rules
- Validate
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:
H-106 KHO_V
result =
com.pegarules.generated.myruleset_mylibrary.MyFunction( params
)
using the exact case for the function name. B-18409 SDAS
3/21/06
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. CLINIC notes 2/11/05
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.
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.
How functions
appear in generated Java
In the generated Java, function calls look like:
pega_rules_default.getCurrentTimeStamp();
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): F-127
Vidoni
- Stop the application server.
- Delete the text file
PegaRULES_Extract_Marker.txt
file.
- Restart the application server.
This adds an INFO line to the Pega log noting the
re-extraction.
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.
SR-1441
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, 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.
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. OLSOK 5/16/06
pyUsage
, a description of what the parameter is
and how it is used (for JavaDocs)
pyDataType
, available to document the Process
Commander 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
page
pyMode
, can document whether the parameter is an
input or output value.
Advanced note:
Return values
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 Process Commander 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 OLSOK 5/16/06
- The
pyIntrinsic
, reserved for future use to
support efficient inline code generation. OLSOK
5/16/06
Advanced note:
Other properties of function rules
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. OLSOK
5/16/06
Advanced
note:J2EE enterprise
support
When 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. C-2144
About Function
rules