Saturday, January 11, 2020

Iterating through a Datapage - Things you need to be aware!

Happy New Year! Hope you all are doing fine!


I have been in a number of projects and doing a lot of other stuff and were very busy in the last quarter of 2019. Yes, I am still very busy, but just wanted to let you know this Beaver is still around!


Upcoming CLSA Guide


After the 1st CLSA Guide book, I had planned to write another one, focusing on the Pega CLSA Application Build itself!

How does that sound? A book that teaches you how to analyse open-ended exam questions, how to design and implement your solution, and last but not least - presenting your answer in a way that is easy for the examiners to understand!

I had long started on that, but due to my busy schedule, it had to be put on a lower priority. So when will it be released? I am not sure, but looking at my schedule, it could be around Apr 2020 time frame.


Anyway, now and then, I would want to share some experience with you. This first sharing, will be about Iterating through a datapage.


Iterating through a Datapage - Things you need to be aware!

Due to my current limited time, I will only state down the key-points, and would not be able to go into the details. So the prerequisite to understand this is at least a Pega CSA or SSA, one who knows Activity. So let's start...

Iterating through a datapage in an activity is very common. The following is a simple example that I often encountered:
Iterating through "D_GetScheduleList[Date:Param.StartDate].pxResults"

Where the "Loop" is configured to repeat "For each embedded page". Within the loop, the above is simply doing some steps for each element of the list (the example just simplified it to a single "Property-Set").

All these seem sound and good, however, there are 3 problems:
1) What if the datapage returned exception or error?
2) You are invoking the datapage continuously, is this necessary? If there was no caching, you would be invoking the database multiple times!
3) What if the results of the "D_GetScheduleList" was modified in the middle of the looping? For example, during the looping someone modified the backend data, and it fetched a different copy?

To check for errors, you could do a test within this activity, however, a better approach is to leverage on the OOTB datapage behaviour. In this case, checking the .pyErrorPage.

Next, how do you ensure that you do not invoke the datapage multiple times and also to ensure that you are iterating a fix list? Well, the easiest way is to use a Page-Copy to invoke the "D_GetScheduleList[Date:Param.StartDate]", and saving it to a Clipboard page, then using this Clipboard page for the iteration!

For example, in the How-to Guide: Creating REST Service and REST Connector, I had demonstrated doing this for the REST Datapage.




Invoke the datapage using “Page-Copy”. With the following:
CopyFrom: D_DBRestConnectorPOST[Param.name]
CopyInto: TempD_DBRestConnectorPOST
Step 1 of InvokeRestConnectorPOST Activity

Where the "TempD_DBRestConnectorPOST" is simply defined as the same type as the datapage itself, as follows:
Pages & Classes Tab of Activity That Invokes the Datapage
Next, check for error, by checking the existence of the "pyErrorPage", as follows (using some function in the When):

@PageExists("TempD_DBRestConnectorPOST.pyErrorPage")

Then if it is ok, you would now iterate using this "TempD_DBRestConnectorPOST" instead of the "D_DBRestConnectorPOST[Param.name]". Got it?

Lastly, of course, remember to clean up all the pages!

Simple?

Books Giveaway!


 I am planning some books giveaways, which I would like to send to those interested. To participate, go to https://www.goodreads.com/DebunkumBeaver, and click on the "Follow" button to be informed and participate in this upcoming giveaways event!
Books Giveaways

Good luck and enjoy!