Sunday, 27 June 2021

Application Based Validation in Pega


Why Application Validation In pega?

  • Alternative validation method of Ruleset Validation
  • By using Alternative validation , we can reduce complexity in managing ruleset versions prerequest

How ruleset version prerequest issue can be resolved by using Application based validation?

  • ABV uses application definition to find the rules insteed of ruleset prerequest list.
  • A rule can refer any rules in the application definition ruleset or its built on application


How to enable Application Based validation?

Open any ruleset -> we can select application validation or ruleset validation at the versions tab.


Rules present in application validation enabled ruleset can refer any rule in application definition ruleset stack or in built on application ruleset stacks.

How ruleset validation was used?


If Ruleset validaiton is enabled, then rules present in the ruleset can refer only the rules listed inside the ruleset

How to validate ruleset or application quickly?


Pega provide landing page to validate rules present in ruleset or application. Follow below path to open

Configure -> Application - > Tools - > Validation



How to use collection rule in pega

Collection Rule Overview:

Collection rule is similar like activity rule, this rule we can use to build business logic. It contains orfer collection of steps this will execute in sequence. Similar to the flow action rule , collection rule has pre and post action. we can navigate very easily in this rule as per my experiance.

Rule Class Name: Rule-Declare-Collection


Where we can refer this rule?

We can refer this rule in activity using Collect Method or inside another collection Inside activity:
Calling collection rule from activity

Inside another collection:
Calling collection rule from another collection rule

What is the use of this rule?

We can run multiple functionality like activity, data transform, decision table, decision treee, expression, function, map value, set property, stop , when . In sequence similar like activity using this rule.

Collection rule

What is response Action in each step?

After completing the step mentioned, If I want to perform any particular action when an condition met I can add in the response action .

response action in collection rule

In response action we can call, activity, data transform, expression, function, set property, stop

What is pre/Post actions in Collection rule?

In flow action, we are having pre and post action concept, similarly in collection rule we are having pre and post actions , We can execute some rules on loading collection rule or on completing collection rule.

pre and post action in collection rule

How to create a new function in Pega

 Hi Friends, In this post we will see how to create a new function inside Pega and how to use it by expression builder.


Why we use function on my own way:

Assume a block of java code, which we are using in multiple places in our application. Instead of writing it in multiple places again and again, we can write that java code in a function so that we can reuse that function in our application wherever we need.

Writing a function in Pega is very easy to do. Lets see how to do that.


Below is the java code to get the reverse of a number. We will see how to create this as a function in pega.

class Main {
  public static void main(String[] args) {

    int num = 1234, reversed = 0;

    // run loop until num becomes 0
    while(num != 0) {
    
      // get last digit from num
      int digit = num % 10;
      reversed = reversed * 10 + digit;

      // remove the last digit from num
      num /= 10;
    }

    System.out.println("Reversed Number: " + reversed);
  }
}


First of all we have to create a library, If we are having already a library we can use that. In our case we will create a new library and use it.


So why we have to create library, In library we can keep the java packages so that we can reuse this packages in all the function creating with this library.


Creating a library with a name

Go to Rule Explorer -> Technical -> Library -> Create New


In Library rule, we can provide any package and static variable if  we needs inside the function rule

Note: Any packages or variable provided here is accessible inside function rule.



After creating library We will create a function rule named "ReverseNumber"

Create Function


Modify the java code to use in Pega function. Output will be returned in the variable "Reversed"

Created new funciton

Set output variable data type

Function output

Enable Function ready to be compiled check box once we have modified the code changes. Lets compile the java code to check whether we made any mistakes.


So lets check the code, In activity , by using expression builder selected the function created and provide the input value inside the bracket.

Select function from expression builder

Save the activity rule and run it. Input value provided is 123456789


Lets trace the activity and view the result.

Output
In tracer , we can view the number was reversed.

If you have any doubts , please ask in comment. Thank you Friends.