How to Iterate Over a Value List in Pega (Without Writing an Activity)

As we all know, Pega has different types of complex collections such as Page, Page List, Page Group, Value List, and Value Group.

Although Value List and Value Group are deprecated, you can still see that Pega uses them internally to maintain certain data on the clipboard.

A good example is pxCoveredInsKeys.

In real-world projects, we often get requirements where we need to iterate over a Value List. You can easily do this in an Activity, as the option is available out of the box (OOTB).

But what if your LSA asks you not to use an Activity?

How would you handle this requirement then?

Let’s understand this in detail.

We already know that Data Transforms provide a direct option to loop over a Page List, but there is no option to loop over a Value List. Why?

  --Value Lists are tricky when it comes to Data Transforms.

Data Transforms support “For each page in” loops for Page Lists (which are collections of pages with properties).

However, Value Lists are primitive arrays — they don’t have pages or properties that the Data Transform designer can treat as loop targets.



Recommended way (no Activity required)

Convert the Value List into a Page List, and then use that Page List to perform the iteration.

You can also design this in a framework model so that the same Data Transform can be reused as a plug-and-play component wherever required.

Let’s go through the steps using pxCoveredInsKeys as an example.








In this example, we have a case with three child cases. When I open this case using an Activity and inspect the value of pxCoveredInsKeys, it looks like this:


Step 1 : Creating a generic Data Transform 

Create a data transform which gives you the pxCoveredInsKeys in the form of Pagelist.

Step 2 : Refer your page and convert your valuelist into CSV formatted String

Function ex : @pxStringCSVFromValueList(MyWorkPage.pxCoveredInsKeys)




Step 3 : Now you have the keys in csv formatted string and you can easily convert it into a Pagelist. Create a temporary Pagelist in pages and classes to store the results.

Function ex :  @pxPageListFromStringCSV(Param.KeysInCSVString,ResultKeyList.pxResults,"pyNote","MyOrg-MyTestApp-Work")




This is how your full DT will look like

 



Let's execute this DT and check tracer , our results should be ready in ResultKeyList pagelist.


As you can see the keys are coming as pagelist and the value is stored in pyNote property.


Some recommendations:

1)Try to avoid using value list , They are a deprecated feature which and are no longer recommended by Pega.

2)This example is based on an OOTB value list property which you will find useful in your day to day work in most projects. If you are working with a difference property you can tweak the code accordingly.

3)Always try to design your Data Transform in a way that they can be reused as plug and play components.


Happy learning !


Comments

Popular posts from this blog

Removing Pages Based on Condition from Page List in Pega

Low-code/no-code is the future of software development