Activity methods & its usage – Part 1
Activity Methods - Part 1

Activity methods & its usage – Part 1

Summary:

This article explains about the list of methods available in an activity rule & its usage.

Most of us irrespective of years of experience would be aware of activity rules in PEGA. We would have at least configured one activity with a complex method [Property-Set] πŸ˜›

  • An activity is an instance of class Rule-Obj-Activity.
  • An activity can be used to automate processing.
  • PRPC converts the instructions in the activity into server-side Java code. At run-time, this Java code gets executed to perform the intended tasks.

An activity rule can consist of <<n>> number of steps each of which refers to a method. So, it’s required to understand the usage of methods provided OOTB in order to write an efficient activity.

Let’s explore these methods in detail with a real-time example. The methods are explained in the order of activity rule’s auto-complete values.

Business Scenario

Let us consider a passport application built for OSP organization. End to End process of this application involves Filling Application Form, Evaluating Eligibility Criteria, Verifying Documents and Dispatching Passports.

CALL

  • PEGA recommends limiting the number of steps in an activity to fewer than 25 steps. It is suggested to split logic into multiple activities rather than coding everything in an activity. Grouping logic into smaller units ensures re-usability and maintainability.
  • An activity can be invoked from other activity using the Call method.

Scenario

When an applicant submits the application form, it should be validated and the data should be submitted to an external system.

Implementation

  • This logic can now be grouped into two smaller units,
    • Activity 1 -> to validate collected information
    • Activity 2 -> to submit validated data to an external system.
  • Activity 2 [submitting data to the external system] can be called from Activity 1 [Validating form] using the Call method.

Method Params

  • Call method when expanded shows the list of parameters defined in the called activity along with a checkbox “Pass current parameter page“.
  • Parameters to the called activity can be passed as name-value pairs or by passing the current activity’s parameter page.
  • Selecting the checkbox “Pass current parameter page” ensures that the current activity’s parameter page is getting passed to the called activity which can be referred or updated in the called activity if required.

Debugging

We can debug the execution of the Call method using the tracer tool. Both calling activity and called activity events, parameter page & local variables can be examined in the tracer tool.

Pointers To Remember

  • Call method can only pass parameters to the called activity but not local variables.
  • Call method executes the called activity and once completed, it resumes the processing of calling activity. It uses the same requestor and thread to execute both the activities.
  • Pass current parameter page is mandatory when the called activity has an OUT parameter which is to be used in the calling activity.

BRANCH

  • Branch method functions similarly to the Call method with an exception that, Call method returns the control back to calling activity and resumes the execution of calling activity, whereas the branch method will not return the control back to calling activity. No steps after the Branch are executed.
  • When the system executes a Branch step, control transfers to another activity. Execution of the current activity is paused & the processing of the current activity ends when the branched activity execution is complete.

Scenario

When an applicant submits the application form, it should be validated and the next course of action is decided based on the validation result.

  • If form validation fails -> Applicant should be notified and the form data should not be submitted to the external system.
  • If form validation success-> Form data should be submitted to the external system.

Implementation

  • This can be implemented by having a branch activity to send an email notification when validation fails. If not, logic to send data to the external system gets executed.
When validation fails, branch activity to send email gets executed and the system automatically skips the execution of “TransferFormToXYZ“.

If (Validation fails)
{
The system executes Branch step to send email notification & ends the current activity execution
}
else
{
System skips sending email notification and executes logic to send data to the external system
}

Debugging

We can debug the execution of the Branch method using the tracer tool. Both calling activity and called activity events, parameter page & local variables can be examined in the tracer tool.

When the form validation fails, the branch method is invoked to execute “SendSimpleEmail” after which the execution of calling activity ends [skipping the logic to submit data to the external system].

Pointers To Remember

  • Branch method can only pass parameters to the called activity but not the local variables.
  • Branch method executes the called activity synchronously using the same requestor and same thread.
  • Branch should be used when the system does not want to execute steps after branch in the calling activity.
  • Most of the OOTB APIs like createWorkPage, UpdateWorkObject, Validate makes use of branch method to skip activity execution in case of errors.

COLLECT

  • Collect method is used to invoke collection rule during the execution of an activity.
  • Collection is a rule instance of class RULE-DECLARE-COLLECTION.
  • Collections enable us to define a set of rules that are executed in sequence under the specified conditions and contexts.
  • Collection rule is available under the Decision category in records explorer.

Let’s now look into a real-time scenario to implement collection rule whereas a detailed explanation of collection rule & its back-end execution will be covered in our upcoming post.

Scenario

The passport verification process involves a different set of business logic to evaluate for Millennial [Age below 30] and Senior Citizens. Based on the outcome of the validation, Applicant & OSP Manager should be notified of the status of the application.

Implementation

  • The applicant provides their Date of Birth and age should be calculated from DOB to decide the category of the applicant [Millennial/Senior Citizen]. This can be handled using pre-action available in the collection rule.
This image has an empty alt attribute; its file name is image-41.png
  • To validate the information, we can have activity/data transform specific to each category [Millennial/Senior Citizen] which will be conditionally invoked based on the age of the applicant. The entire logic can be placed in a collection rule which will act as a single source of reference.
  • As per the requirement, once the validation is performed email notification should be sent to the applicant on the status of the application. Emails with different subject/content should be sent for Millennial and Senior Citizens. This can be implemented by configuring the “SendSimpleEmail” activity as a response action of step/category.
This image has an empty alt attribute; its file name is image-42.png
When the Millennial application is processed, an email will be sent with verbiage specific to Millennial.
  • As per the requirement, the OSP Manager should be notified of the status of the application once all the validations are completed. This can be handled using post-action available in the collection rule.

Method Params

Collect method when expanded shows the list of parameters defined in the collection rule along with an option to “pass current parameter page“. Parameters of the collect method act similar to Call/Branch method.

Debugging

We can debug the Collect method using the tracer tool without enabling any additional settings in the tracer. Page context, Parameters & local variables used internally can be easily examined using tracer. A sample tracer event of application with category Millennial [Age<30] is shown below.

When IsApplicantMillenial is true, it executes corresponding activity VerifyMillenialApplication

Pointers To Remember

  • The need for collection should be wisely decided during our implementation. A few examples are: calculating discount rates in online shopping based on the customer profile, calculating premium in insurance based on jurisdiction, calculating loan interest based on the principal amount, etc.
  • The collect method can only pass parameters to the Collection rule but not the local variables.
  • Collect method executes the Collection rule synchronously which uses the same requestor and same thread.

JAVA

  • Java is a method that is used to include custom java code in an activity.
  • Java code in activities is referred to as inline Java. Basic java coding skill is a must to implement/debug these methods.
  • A real-time scenario to use Java code is discussed below.

We use java in writing functions to promote re-usability which can be explored in our upcoming post.

Scenario

Assume that application/case information is received in JSON format from an external system . PEGA should parse the incoming JSON and map it to the clipboard for business processing.

Implementation

  • Custom java code can be used to parse the incoming JSON object.
  • Message is a local variable that contains the actual JSON.
  • adoptJSONObject() is an Engine API in PEGA which can be used to parse the incoming JSON into a clipboard page.

Debugging

  • We can’t debug Java code directly using the tracer, instead use log messages.
  • Let’s now see how to debug the incoming JSON string in the above-mentioned java snippet. Custom code can be added to log the message whenever required. It can be verified in PEGA logs after its execution.
java code with debugging enabled.
PEGA logs which show the incoming JSON. This can be used for debugging.
Clipboard structure after the execution of the java code.

Pointers To Remember

  • The usage of Java code should be minimal in activity. If required, it can be converted into functions and can be directly invoked from the activity using the “Call-Function” method.
  • Local variables in activity can be directly used in java code without any explicit declaration in code [like Message variable in above snippet].
  • Proper exception handling should be done during inline java usage.
  • Below are few commonly used snippets which might be required when writing a basic java code for our application need
    1. Initializing a clipboard page from java code
      • ClipboardPage <<PageName>> =null;
    2. Accessing data from parameter page
      • String <<var>> = tools.getParameterPage().getString("<<Param Name>>");
    3. Setting value to a parameter page
      • tools.getParameterPage().putString("<<ParamName>>", "<<Param Value>>");
    4. Referring DSS value in java code
      • String <<var>> =tools.getSystemSettings().getDynamic(<<Ruleset>>, <<DSS Key>>)

QUEUE

  • Queue method functions similar to Call method with an exception that, Call handles the execution synchronously in same requestor, whereas Queue handles the called activity execution asynchronously in a different requestor which promotes parallelism.
  • A requestor of type “App” will get initiated for the queued activity execution.
  • Access group of the App requestor will be the same as that of the access group of the logged-in user who queued the activity for execution.
  • Control will be immediately passed to the calling activity since the queued activity execution happens in the background.

Scenario

Whenever a passport application is received, OSP Managers should be notified and the processing should continue.

Implementation

  • The above requirement can be split into two smaller units. One to send notification and the other to process the request.
  • The processing of requests is independent of the email notification sent. Hence this logic can be executed in parallel using the Queue method.
  • Email notification is sent asynchronously using the Queue method, whereas application validation is dependent on parse information hence it’s invoked synchronously using the call method.
  • Just for our POC, the Wait method is used in the queue activity to show the app requestor getting created at the back-end.

Debugging

Since Queue executes the activity in different requestors, it can’t be directly debugged using the tracer tool. Instead, we can debug using a few alternatives listed below.

  • Queue method in activity can be replaced with the Call method which enables debugging using tracer tool. Once debugging is done, revert the changes made.
  • We can use Log-Message method inside queued activity to print the required information in PEGA logs.
  • Queue activity can be made to wait for some time interval using the “wait” method and the app requestor created at the back-end can be directly traced from the Requestor landing page.

Pointers To Remember

  • Queue method can be used for executing any business transaction logic asynchronously. A few examples are sending emails, updating an external table/data type, etc.
  • Queued activity runs on the context of the step page mentioned in the Queue step. Parameters passed from calling activity will be readily available in the queued activity.
  • Queue method can be preferred in below scenarios
    • When business logic can be executed without any dependency.
    • When performance is a consideration.
  • Queue method can only pass parameters to the queued activity but not the local variables.

We hope you have learned something new in this post. Let’s explore more on other methods in our continuation post [Part 2].

Part 2 will cover the following methods.

  • Activity-Clear-Status
  • Activity-End
  • Activity-List-Add
  • Activity-Set-Status
  • Apply-DataTransform

Stay tuned for part 2 😎

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

29 comments
  • Why do you have upcoming article section when you are deviating from what you write there- are you having it to fool your readers who come to see your post? Do not publish article just for the purpose of article count. This is very bad. When you posted about broadcast I was so proud of your site but publishing silly articles like this will just leave us disappointed. Even property set is a method and you don’t have any rights to mock on developers using that. First of all you need to promote using best practices of data transform rather than telling you being a blog writer who is a clsa telling the entire world that you wrote property set. Very funny you and your stupid jokes.

    • Thanks for taking time to write this comment @Nikhil Jha Kulkarni
      1) Apologies from our end for deviating from what’s mentioned in upcoming articles. It’s because of some unavoidable situation which we can’t explain in comment. We care for our subscribers & that’s why we put in additional effort to share knowledge. We don’t have any intention to fool our readers rather we value their learning.

      2) You mentioned this as silly article. We guess you are a big expert in writing activity who has practically used all methods available. If so, then this post will look silly for you. We have received feedback from many in LinkedIn saying this post is useful for them & they are waiting for Part 2. We are still happy to post silly topics if it even helps one person learning.

      3) You just say we mock at developers on using Property-Set. You only know us posting articles in OSP, apart from this we address lot of PEGA problems that comes to us through LinkedIn, we help train individuals who are struggling with their official life etc.. Anyone can put their thoughts about helping others in words but only few can convert that into action. We feel like we are among that few who proves that in action. We don’t have that cheap behavior of mocking at developers as others do.

      4) You said to teach about best practices. As a blogger, we feel that first we should make everyone understand all the available concepts and then to pick the best from those mentioning its pros & cons. You can’t straight away tell them this is best practice without giving them idea on what other alternative is available.

      Happy Learning from OSP 😊

    • Hey Nikil,
      Is there any wrong, if a CLSA tells he/she created activity with the “Property-Set” step? I didn’t feel anything like mocking developers in their sarcasm in this entire article.
      If you feel an article silly, Please skip that article. Some persons like me may find the article useful. Don’t discourage the people from your self needs. Freshers also visiting the blog regularly along with you (Considering you to be a GREAT LSA). They will expect a basic article like this.

      @OSP guys – I am one of the regular followers of this blog. You guys doing awesome work !! Keep up the spirit. Keep contributing more to the Pega community. Many Freshers like me found this blog very useful in understanding basics & core things. Thanks a lot. GOD BLESS!

      • Happy to hear these words form you @Joel David

        Apologies for the late response. Definitely we will make sure our contribution towards the PEGA community is high.

        Happy Learning from OSP 😊

        • Hi OSP Team,
          I found the posts in this blog are very useful to me. I am primarily working on a different technology and started working on Pega BPM recently. I found you posts easy to understand , learn and are boosting my confidence that I can become a better Pega developer.

          Nikhil has to understand that all kind of people(Beginner, Intermediate, Expert etc.) will read the blog. Even if some post/topic is simple, it will be still helping someone like me. If you dint like the article or finding it simple, you suggest for a topic what you are looking for.
          OSP team is not doing this for any benefit. They are doing it as a service out of their passion. You are people with nice hearts.

          I am learning a lot and awaiting for more posts.

  • I have a request which I want to communicate on behalf of the readers of this blog. These are self explanatory and I feel you could have taken other topics where it would be helpful for all. The way you have written this article is not like your previous articles. Actually to me this is looking like you have not posted any article for 3 weeks and then published this one is making me think that you are doing this just to keep your blog active. Taking time is ok because I do understand after seeing your LinkedIn profile that you do this after your regular work. But even if you take time,bpublish something useful for the readers. This is not what we want team. Hope you understand my concerns. Just telling so that you can do what many wants as everyone time including yours is very precious. I am not willing to share my identity that is why I never comments in any of the previous articles though they were awesome. Please do not force for my identity. Please do not focus on increase article count, focus on quality.

    • Thanks for your genuine comments @Pushpamallikarjuna Komalasetti.
      1) You might see this part 1 post as useless since most of us would be aware of call/branch/queue methods discussed in post. But you will find its usage when you see continuation post which explains other methods namely Call-Async-Activity, Connect-JMS, Connect-FTP, Connect-MQ, Publish-Notifications etc…

      2) We do agree that these methods are self explanatory. But we thought of bringing you the usage of methods with a real time scenario for each. You won’t find any articles outside for reference which explains you about methods with real time examples. We do add few more information on how to debug & pointers to note which you will feel the importance when you use that in your project/application.

      3) We never work for the namesake of article count. We are 3 CLSAs in team, if each of us could take 1 article each per week it would have been close to 30+articles by now. But we just have 10+ and the only reason being is, we work as a team to publish article. We sit together, we discuss on topics, details to include, POCs & business scenarios, review and then post it as a team. We never urge to publish article just for count.

      From your comment we just understood to prioritize articles based on the readers need. We will definitely work on getting it done.

      We will never ask for your identity & you can reach out to us anytime with any kind of feedback. We only focus on our subscribers learning curve & nothing more.

      Happy Learning from OSP 😊

  • Nothing is useless as a part of learning. .
    OSP team is doing a great job educating the learners in Pega. This blog is a great worth for everyone who has knowledge on Pega despite the badge we own.

    • This is one of the rarely used methods in an activity rule. As we have obj-refresh-and-lock to obtain a lock of a particular record [step page], similarly Page-Unlock can be used to release lock of the specific record [step page].

      To keep it simple, this method can be used to release the lock on a particular record if the lock is already held.

  • Good job OSP. To the people who are commenting bad things here ,please stop reading the blog. If you are already an advanced level or expert you can learn things in your own by writing your own code and debugging it. Have some respect to the bloggers who take time to post useful articles. They are very helpful to the entry level folks like me and I really respect what they do. We can only request or recommend topics from bloggers but we don’t have right to criticize. At the end all I say is thank you OSP, keep the spirit of educating and sharing knowledge with us. Great effort !!!

  • Very useful information regarding activity methods and easy to understand, please upload the remaining methods also.

  • Wonderful read. Small correction. A child BATCH requestor(Not APP) is created when Queue method is invoked. I guess the APP requestors in the screenshot are there for some service execution. It is also evident from the log text that Queue ueses one of the available batch requestors. Like BATCH-1.