Function alias – its Configuration, Usage & Execution
Function alias

Function alias – its Configuration, Usage & Execution

Summary:

This article explains about the configuration & usage of the function alias along with its invocation from the report definition & other business processing rules.

Please go through our previous posts to understand the configurations in Report Definition & its detailed usage.

What is a Function?

  • Functions are a series of code (Java)/ predefined formula (SQL) that executes a specific task.
  • Functions usually take in argument(s), process it, and return a result.
  • Functions allow us to reuse code instead of rewriting it everywhere.

Types of Function

Based on its definition, functions can be broadly classified into two types,

  • Predefined Function
  • User-defined Function

Predefined Function

These types of functions are built-in which can be directly used by the applications by passing the pre-defined set of input parameters.

  • In Java, length(), equals(), time(), subString(), upperCase(), lowerCase() are some of the built-in functions.
  • In SQL, CONCAT(), TRIM(), LOWER(), UPPER(), REVERSE() are some of the built-in functions.

When we call any of the predefined/built-in functions in our program, a series of code related to the corresponding function runs in the background and produces a result.

User-defined Function

These types of functions are not built-in and are written/developed by the developers to satisfy application specific needs. In Pega,

  • Writing Java function (Rule-Utility-Function) to generate a word document, type cast data, parse json/xml are some of the user-defined functions.
  • Developing SQL functions (Rule-Alias-Function) in Pega to find elapsed SLA time, day of the date, text masking are some of the user-defined functions.

When we call any of the user-defined functions in our program, similar to predefined functions a series of code related to the corresponding function runs in the background and produces a result.

Let’s now get into actual discussion on the configuration & usage of the function-alias

What is Function Alias in Pega?

  • From OSP dictionary we would define Function alias as the rules that promote the usage of the function (Java/SQL) to the users (non-developers ) who maintain business rules (Decision tree, Decision table, When) or create/configure reports in Production.
  • Function alias is also used to help developers to build reusable codes using complex SQL expressions.

Types of Function Alias in Pega

  • Function alias are rule type of class Rule-Alias-Function and are available under Technical category in the Records explorer.
  • Alias function in Pega can be broadly classified into two types based on its reference,
    • Alias for SQL expressions
    • Alias for Java functions

Alias for SQL expressions

These are the function alias rules that provides compact packaging of complex SQL expressions that are needed in some circumstances when querying the database.

Configuring Alias for SQL expressions

  • These type of alias is always created in the Embed-UserFunction class.
  • The configuration of the SQL expression alias can be categorized into three different sections,
    • Input Parameters
    • Presentation
    • Source

Input Parameters

  • This section defines the list of input arguments required to build the SQL expression.
  • Data type defines the data type of the input parameter and type field defines how the input parameter will be presented in the Report Definition when invoked.
  • Type as drop-down menu can be sourced with custom list or the property reference (comma separated values).

Presentation

  • This section defines the design-time & run-time design configuration of the alias rule.
  • Input parameters defined in the above section can be referred as {1}, {2} and so-on based on the order of its definition.
  • Pattern template and Echo template helps the user to see the description about the alias rule during design-time.
Configuration of Function Alias in a Report Definition
  • Output format field defines the control (Rule-HTML-Property) which determines how the result should be presented in the UI.

Source

  • This section has the definition of the actual SQL expression.
  • We can refer JSP tags in the source section if needed.
  • We can also refer Java snippets in the source section.
  • Each alias rule can be uniquely identified using its function signature defined in Generated Output tab. It’s also possible to invoke an alias rule from another alias rule using its signature.

Invoking alias for SQL expressions

  • Alias with SQL expression can be invoked from the report definition rule by developers or can be used by Business users (non developers) during the report creation/configuration from the report viewer.

Alias for Java functions

These are the function alias rules that promote the usage of functions (Rule-Utility-Function) to Business users (non-developer) who maintain decision rules, decision trees, when rules, etc.. with a list of parameters & descriptions.

Configuring alias for Java functions

  • These type of alias is always created in the class other than Embed-UserFunction. For example: @baseclass, Work-, Data-,etc…
  • The configuration of the java function alias can be categorized into three different sections,
    • Function reference
    • Input parameters
    • Presentation

Function reference

  • This section allows us to select the Java function rule for which the alias is being created.

Input parameters

  • This section displays the list of input parameters from the selected function for which the description, Property reference, default value, etc.. can be updated.
  • In the above example, the input parameters for the function rule are readily provided in the alias rule, which an end-user/citizen developer can directly refer this in all the business rules (Decision tree, Decision table, When, etc..)

Presentation

  • This section allows us to edit the return type (not recommended) & the description of the function. A more meaningful description can be provided to make it easier for the citizen developers.

Invoking alias for Java functions

  • An alias with Java function can be referred in any of the decisioning rules (decision tree, table, when rule) that can be managed by the end users.
  • As we see, the input parameters are pre-populated based on the configuration from the alias rule and it makes it more easier for the end users who doesn’t have any technical knowledge.
  • Alias rule created in class other than Embed-UserFunction cannot be accessed/invoked from the report definition rule.

Business Scenario

Let’s consider the scenario where OSP organization has a claims application, Customers can raise a claim anytime in the system. Customer information namely Customer name, email, CLV will be available in Pega as a separate data type.

We are asked to create a report which would categorize the customers based on their CLV as shown below.

If CLV>75, -> Platinum Customer,
Else If CLV>50 -> Gold Customer,
Else If CLV<50 -> Silver Customer,
Else -> Not Classified

Implementation

We have used v8.4 for implementing this POC

  • Customer information (OSP-Data-Customer) are maintained in a separate data type in Pega.
  • Function alias is created in Embed-UserFunction class with SQL logic to return customer type based on the CLV value.
  • A Report definition is created to show the customer details. From the fetched CLV, customer type is manipulated using the created function alias rule.

Execution

  • Let’s now run the created report definition rule to examine the function alias invocation to categorize the customer based on the CLV.
  • The manipulated function alias results will be available in the clipboard as shown below. It can be referred in UI as <<PageName>>.pxResults(xx).pyTextValue(xx), where pyTextValue is a valuelist.

Pointers to Remember

  • Function alias are rule type of class Rule-Alias-Function.
  • Alias can be created for a SQL expression or a Java function.
  • Alias rule created for a SQL expression should be of class Ember-UserFunction & can only be referred by developers in the report definition rule or by the users (non-developers) in the report viewer while creating or configuring reports.
  • Alias rule created for a Java function can be of any class other than Ember-UserFunction & can be used by the users in any of the business rules namely decision table, decision tree, when rules, map value, etc.
  • Function alias promotes reusability.
  • Function alias can be sourced as a pure SQL/ using JSP tags/ using Java snippets based on the need.
  • A function alias can also invoke another function alias by using the function signature.

We are now at the end of the post. We hope now the basics of configuring and using function-alias with its type is clear.

We are glad to publish the article requested by @ LaxmiKanth on “Function Alias”. If you want us to publish any articles of your choice, please fill out this form & we will make sure it gets published.

Stay tuned for lot more posts on Reports & Case Management 😎

OSP TEAM
Written by
OSP Editorial Team

Recent Jobs from our community

loading
View more Jobs on OSP Forum
Join the discussion

Feel free to post your questions here about this topic if any. We will definitely get back to you ASAP !!!
If you have any off-topic questions, Let's discuss at OSP Forum

7 comments