In the realm of Pega applications, functions play a critical role by executing specific tasks, taking in arguments, and returning results. However, there's another powerful tool at developers' disposal: function aliases. Function aliases are custom functions created by developers to meet their specific requirements and streamline their work. A notable difference between functions and function aliases is that while functions are executed on the Pega side, function aliases can also be executed on the database side.
Function aliases are a rule type of class Rule-Alias-Function and are found under the Technical Category in the Records explorer. Based on their usage, function aliases in Pega can be categorized into two types:
Function Alias for SQL Expression (only for report definition)
Function Alias for Java Expression (for decision rules, etc.)
Function Alias for SQL Expression
The function alias for SQL expression allows developers to write customized functions within the report definition to meet specific requirements when querying the database.
Configuration — Function Alias for SQL Expression
Exclusivity to Report Definition: The alias rule created for SQL expression can only be referred to within the report definition rule. It is not available for use in any other rules in Pega.
Class Requirement: When creating a function alias for SQL expression, it must always be created in the Embed-UserFunction class.
Input Parameters
When creating a function, it’s necessary to pass the required arguments. The input parameters section defines the list of arguments needed to build the SQL expression. The fields to be filled include:
Name: Defines the name of the parameter
Description: Provides a description of the parameter
Data Type: Specifies the data type (integer, text, boolean) of the input parameter
Type: Defines how the input parameter will be presented while invoking it in the report definition rule.
Presentation
The presentation section defines the design time and run-time configuration of the alias rule and includes:
Return Type: Specifies the type of data that needs to be returned
Pattern Template and Echo Template: Serve as descriptions to identify the context and act as templates to build your function logic. Parameters defined in the input parameter section can be referred to as {1} for the first param, {2} for the second param, and so on.
Output Format: Determines how the result will be presented or displayed in the user interface using the control (Rule-HTML-Property).
Source
The source section allows developers to write an SQL expression to build the core logic for the function alias.
Invoking Function Alias in Report Definition
Invoking a custom function alias in a report definition is straightforward:
Click on the functions button available for the column source.
Select the function from the list.
After selecting the function, provide the required inputs as defined in the parameters section of the function alias rule.
By leveraging function aliases, developers can create tailored functions that enhance the flexibility and efficiency of their Pega applications. This powerful tool enables the handling of complex requirements directly within report definitions, streamlining the development process and improving overall functionality.
-Team Enigma Metaverse
Comments