Aggregate Properties and Use of Indexes inside Aggregate Properties in Pega
In this blog article, we will talk about two things
- Aggregate properties and its usage
- various Indexes (<CURRENT>, <APPEND> etc..) that can be used inside aggregate properties.
Update: The activity rule methods remains the same across different Pega versions. The screenshots in this blog article were reused from Pega 7 version. Use this blog article to learn the concepts and you can try it out in the latest versions as well.
What are aggregate properties?
Properties help in storing the data. Data can be simple single value or can be grouped and stored in pages.
Aggregate properties helps in grouping the data.
Say for example – Policy Name, Policy Date, Policy period, Expiration date all these single value properties are related to Policy right. Here we can store all these values under a page property called Policy.
Now if multiple policies are applicable, then we can save multiple policy pages under an aggregate property.
In this scenario – you can form a page list / Page group.
Aggregate properties
1. Value list – This type is kind of single value property, but can contain more than one values. The values are arranged in an ordered array.
2. Value group – This is same like value list property, but the values are arranged in an un-ordered array.
3. Page – This type can contain more than one single value property and its value embedded inside.
4. Page list – This type is a collection of Pages in an ordered array
5. Page group – This type is a collection in pages in an un-ordered array.
What is Value list property type?
Every single value property contains a single value. Agree.
I am saying some single value properties can contain multiple values!! …………Confused !!
The best example is phone number. Phone numbers can be – Home number, office phone, mobile phone but they are all phone numbers
Now Instead of creating 3 properties
- HomePhone
- OfficePhone
- MobilePhone
You can create a single value list property to hold all the values.
PhoneNumber – Value List property.
Let’s go ahead and create a new value list property.
Now a PhoneNumber value list property is created.
How do we use a value list property in activity/data transform?
Step 1: Create a test activity.
Step 2: Add a property-set and try setting a value like, how we do for single value property and save the activity.
You get an error – Cannot set a String to a string list property.
This is because this is a specialized single value property type that contains a list of values.
So, when you hear list, what comes in your mind – array.
Aggregate properties can be compared to array objects in Java.
Step 3: Let’s save the value in the array list.
I am able to save it.
Step 4: Run the activity and check the clipboard for ActivePage.
Why no value set on page?!!
Cool, generally for aggregate values, you need to expand the ActivePage.( Embedded)
You can set more than one values inside the PhoneNumber property
Check the clipboard.
Now let’s check how to use the values inside an activity loop.
You can loop the value list property. Click on the loop
Repeat – For each element in value list ; Value List property – PhoneNumber
This will be like
For ( i=1; i >=(Max length); i++) ( Note: Max length is 3 here)
{
}
Note: You can also do the same property-set in 3.0 step
– <CURRENT> will be auto populated with ‘i’ value. It means in First loop, it will refer = 1
– So, in first loop, PhoneNumber (<CURRENT>) = .PhoneNumber(1).
Trace open the rule and run the activity.
Let’s check the param value in each loop.
Note: Param.pyForEachCount will contain the Loop Index ( ‘i’ value)
You can also bring the (<CURRENT>) to left hand side of a property-set to update/ set the values in valuelist property.
What are the Indexes you can use inside an aggregate property?
- <APPEND> Index
- <LAST> Index
- <INSERT> Index
- <PREPEND> Index
- <CURRENT> Index
<APPEND> Index
– This index is used, when we need to append an element to the highest index value.
– This is used only in target properties – It means properties on left in property-set method.
– This is applicable for value list and page list properties
I can set all three Phone Number values using <APPEND>.
Instead of hard coding, you need to do this.
Run the activity and check in the clipboard.
Good.
Say if there are already 2 phone number values in PhoneNumber valuelist property ( PhoneNumber(1) & PhoneNumber(2))
Then appending will add PhoneNumber(3)
<LAST> Index
– This index is used to retrieve the last element in value list/ value group property.
– <LAST> will be replaced with the Highest subscript or index
– This is applicable for value list and page list properties
We have populated three phone number values using APPEND.
Now let’s use LAST
Step 1: Add a new step and update the last Phone Number with ‘1111111111’
Step 2: Run the activity and check in the clipboard.
In the Page list example, you will get to know more about it 😊
<INSERT> Index
– This index is used to insert a new element and its value in a value list / page list property at a specific numeric position
– This is similar to APPEND Index and used only in target properties.
– This is applicable for value list and page list properties
Note: Unlike other Index, here you need to specify the subscript value, where you will be inserting
(<INSERT>1) – It can 1, 2 or 3 (subscript value)
The Difference between <APPEND> and <INSERT> are
– <APPEND> always appends a new element to the highest index value (Last), where <INSERT> Can append/Insert to any index value.
In the above example, I have 3 phone number values. IF I need to insert a new phone number to position 1 – PhoneNumber(1), then all the other values are pushed down by One position.
Let’s test it.
Step 1: Add a new step and Insert the Index.
Step 2: Run the activity and check the clipboard.
We have successfully inserted a new element in position 1 and all remaining values are pushed one position down the array.
<PREPEND> Index
– This index is used, when we need append an element to the first Index.
– This is the exact opposite of APPEND Index.
– This is applicable for value list and page list properties
In the above example, we inserted Phone number = “1111111111” in the first position.
We can achieve the same <PREPEND> index.
Step 1: Add a new step with <PREPEND> index.
Step 2: Run the activity and check in the clipboard.
<CURRENT> Index
– This index is used, when we are inside a loop and want to update the properties in the current loop. We already tested 🙂
– Current in used in all types of aggregate properties. You can use it in a page list, page group, value list or value group.
Let’s get back to our property type discussion😊
What is Value group property type?
This is same as Value list with the exception that the values are unordered. (not ordered in 1,2,3 etc)
The perfect example can be email address. You can have two email address.
- Personal
- Official
Instead of creating 2 properties, we can create a single value group property – EmailAddress
Property type – ValueGroup
How to use a value group property in an activity/data transform?
Step 1: use the same test activity
Step 2: Add a property-set.
Instead of ordered number, you can update it with some text value – Unordered list
In the Email address example, you can update EmailAddress(Personal), EmailAddress(Office)
Step 3: Run the activity and check in the clipboard.
You can trace open the rule and check the parameters inside the loop.
Note: pzForEachSubscript will contain the value group subscript value
What are the differences between value list & value group?
– Value list contain ordered list of single values, while value group contain un-ordered list of values.
– You can use the five types of Indexes inside a value list property, since the subscript( index – 1,2 etc) value can replaced by the Index, but in Value group you can only use (<CURRENT>).
We have an advantage on value group over value list
Say, for example you created the same EmailAddress property using value list. Now, you cannot identify which subscript contains the personal email address. It can be either 1 or 2 right? EmailAddress(1) or EmailAddress(2)
In this scenario, you can make it value group and refer personal email address directly using EmailAddres(Personal) everywhere 😊
Let’s test using value group inside a loop
Step 1: Create a test activity
Step 2: populate the EmailAddress value group property with personal and Office email address.
Step 3: Start a loop and use
Repeat – For each element in value group; Value group property – Email address.
Step 4: Trace open the rule and run the activity.
Open the parameters on each page and check the Test value. You will see email addresses set correctly.
What is Page property type?
– We know that pega stores all the data in the form of clipboard page in memory.
– Pages contain data.
The pages we create in activities or data transform are user defined pages and wipes out once the memory is cleared from JVM ( like you log out).
In some scenario, you need to save some collection of data within the work item.
The best example is address details.
You need to collect all those details and append to work item ( No need to expose)
Here you can create a new property – Address – Page type
Store all the single value properties ( City, state, Zipcode) under the Address – page property
Create a new property – Address and update property type – Single page
Page definition –
What is Page definition?
Remember, whenever we create a new page in activity, we will be specify the page name in pages & class.
Every page will contain a page definition class – pxObjclass.
For a page property, we no need to specify in the pages & classes tab 😀
So you specify here.
Important points to remember in Page definition configuration
– You can specify any concrete class here. In the above example, I used a concrete class – TVS-Data-Address, so that properties under the address data class ( City, State, Zipcode) can be included inside the Address page.
– If you specify any abstract class, at run time a concrete class can be dynamically referred.
You may see this as kind of reusing – dynamic referencing
– You can also use $CLASS or $ANY for dynamic referencing
To check, you can open the pagelist property ‘pxResults’ and check the page definition.
You know that pxResults will be used in many places to contain the results pages ( obj-browse) – Either work or data any class.
So we specify $CLASS and dynamically refer the class of the in activity / Data transform rule.
How to use page property in a data transform / activity rule?
Step 1: Create a new test activity
Step 2: Update the Address page with address values.
You don’t want to specify the step page ‘ActivePage.Address’ in the pages & class, Since the page definition in the property rule form contains the appropriate class definition
Note: If you use $CLASS or $ANY, you need to specify the class in pages & classes tab.
Step 3: Run the activity and check the clipboard.
You will see the address page populated with all the values.
Note: Page property can also include properties other than single value. You can embed another page, page list, page group, value list or value group inside a page property.
What is Page list property type?
Value list – Collection of single value properties in an ordered list
Page list – Collection of pages in an ordered list
For example – say, you need to store the office address details and residential address details separately in pages.
Here you can create a page list property – AddressList and store both the address details.
AddressList(1) – Office Address
Addresslist(2) – Residential address
Create a new page list property – AddressList
For testing – save as the rule to create another pagelist property – NewAddressList 😊
Step 1: create a new test activity.
Step 2: Populate the address details in AddressList pagelist property.
You can either user <INSERT> or can just harcode it.
Now, let’s see how to populate NewAddressList inside loop
Note: Whenever you are inside a loop, Param.pyForEachCount will contain the subscript value
Step 3: Add a new step with step page – ActivePage.AddressList
Repeat – For each embedded page
Only loop for certain classes – Remember, you can specify the page definition – $ANY and can be dynamically substituted for each page inside page list. So a page list can contain pages with multiple classes.
You can conditionally loop the pages only for certain classes.
Maximum, we leave this empty and loop all pages.
You can do page-copy to copy the loop page inside a destination page.
You can use the (<CURRENT>) Index to copy the AddressList to NewAddressList
Step 3: Run the activity and check the clipboard.
Step 4: Let’s try property-set instead of page-copy
We do this, when we need to copy only few properties ( City, State) not the whole page.
You will see two Indexes used – <APPEND> followed by <LAST>
The reason is as follows
1. APPEND will append a new page , say .NewAddressList(1)
2. In the next step, we need to add few more properties in the NewAddressList page right.
So, we use <LAST> to get the last subscript value – Obviously 1 in this case.
Both APPEND and LAST are substituted with subscript value ‘1’
Step 5: Run the activity and check in the clipboard.
You will see city and state are copied alone
What is Page group property type?
Collection of pages in un-ordered list.
Like the same we discussed value group
Here the AddressList, I can configure it to PageGroup property type and set the value to
AddressList(Office) & AddressList(Residential)
Create another new page group property – NewAddressList for testing purpose
Let’ test using same activity.
Step 1: Populate the page group property – AddressList
Remember, we can use
Note: Like Param.pyForEachCount, pxSubscript will hold the subscript value.
Step 2: Create a new step looping the AddressList pagelist property.
Repeat – For each embedded page
Step 3: you can make use of the pxSubscript property to substitute the index dynamically.
Step 4: Open the tracer and run the activity.
You can see the pxSubscript will contain Office and Residential inside each loop.
Step 5: Now check the clipboard, if all the values are populated in NewAddresList property.
What are the difference between Page list and Page group properties?
The differences may look similar to the difference between value list and value group types.
Hope you are clear with the aggregate properties and different indexes you can use inside.
– Page list contain ordered collection of pages, while Page group contain un-ordered collection of pages.
– You can use all the five types of Indexes inside a Page list property, since the subscript( index – 1,2 etc) value can replaced by the Index, but in Page group you can only use (<CURRENT>).
– Page list – Param.pyForEachCount will contain the subscript value inside loop. Page group – .pxSubscript will contain the subscript value inside loop