How to retrieve records from a Data Type through Activity in Pega Platform Application

Coach Abhishek
8 min readFeb 20, 2023

--

Data Types are used in Pega Platform Application to store reference data such as a list of cities, or customers, products, etc. in form of table records.

If you would like to learn more about the fundamentals of Data Types, and how to manually add records to it, you can go through the article given below.

The records can also be created in a Data Type in real time through an Activity rule or a Savable Data Page. You can read the below blog to learn about the method to create the records through an Activity.

After the reference data is stored in a Data Type in form of table records, you would need to retrieve or read it in order to use it in your Pega Platform Application. For example — you may need to display a list of cities, stored as records in a Data Type, in a drop down list in a user form. Or you may require to retrieve the details of a specific customer, stored as a record in a Data Type, in order to update the details, and then save it back to the data type.

The data records can be read from a Data Type through a Data Page or an Activity rule. The use of the activity rules is not regarded as a best practice anymore. However, the activity rules continue to play a dominant role in certain areas of the development of a Pega Platform Application. Hence, it is equally important for a Pega developer to remain well versed with the activity rule.

Let’s look at the approach to read records from a Data Type through an activity rule.

Pre-requisites

  1. Data Type
  2. Activity

For demo purpose, I’ve already created a Data Type named User, and added some user records to it. As shown below — User ID, First Name, Last Name, DoB, Email address, Mobile and Marital Status — are the fields added to the Data Type. I’ve chosen the User ID field as key to uniquely identify the records. Note that the class of the Data Type is MyOrg-Data-User.

User Data Type

Additionally, I’ve created an Activity rule named GetUserRecord. I’ve applied the Activity to the Work class (MyOrg-MyDiv-Beta-Work) and a ruleset of the implementation layer as shown below. You can create your activity in a class and a ruleset most suitable for your requirement.

GetUserRecord Activity

Having done with the pre-requisites, let’s go through the method to read a single user record, and that to read a list of records from the above Data Type through the activity.

Method — to read a single user record

Step# 1 — Create a new clipboard page of the Data Type class

Firstly, you need to create a new clipboard page (essentially an object in memory) of the class of the Data Type (MyOrg-Data-User) using the Page-New method of the activity. As shown below, I’ve named the page as UserPage. You can choose any meaningful name for the page.

Page-New method

Make sure to list the page name and its class in the Pages & Classes tab as shown below.

Pages & Classes tab

Step# 2— Load a specific record onto the clipboard page in memory

Secondly, you need to use the Obj-Open method of the activity to load a specific user record by its key (UserID) onto the above clipboard page in memory. For example — In order to load the record with UserID of U-002 from the User data type onto the UserPage, you would need to fill the details in the Obj-Open step as given below.

  1. Enter UserPage as the Step page
  2. MyOrg-Data-User (class of the data type) as the OpenClass
  3. UserID as the PropertyName
  4. U-002 as the PropertyValue

Note — Because we’re only trying to read a record, and not to update it, there’s no need to select the Lock and ReleaseOnCommit check boxes.

Obj-Open method

This marks the end of the configuration required in the activity to load a single record onto a clipboard page.

Step# 3— Save and Run the activity

Next, save the activity if not done already, and afterward run the activity by clicking on Actions -> Run as shown below.

Run the Activity

It would pop-up a window as shown below. Click on the Run button.

Run the activity

If there’s issue with the activity configuration, you would see a success message as shown below.

Success message

Step# 4— Verification

Lastly, let’s verify the result in the clipboard. Switch over to the Standard thread as shown below.

Switch to Standard thread

Thereafter, look for the UserPage in the left pane and select it. You would find the specific record loaded onto the page as shown below.

UserPage in the clipboard

Method — to read multiple of user records

Step# 1 — Create a new clipboard page of Code-Pega-List class

In order to load multiple or a list of records from the data type in memory, you need to start by creating a new clipboard page (essentially an object in memory) of the Code-Pega-List class with the Page-New method. I’ve created a page named UserList that would hold a list of user records as shown below. You can choose a different name for the page.

Page-New method

Ensure to list the page along with its class in the Pages & Classes tab as shown below.

Pages & Classes tab

Step# 2— Load a list of records onto the clipboard page

Use the Obj-Browse method to browse/load a group of records from the data type onto the above page in memory as shown below.

Important: Obj-Open method is used to open/load a single data record in memory whereas the Obj-Browse method helps to browse/load multiple records in memory.

Since, I’m trying to load the records from the User data type onto the UserList page —

  1. I’ve entered UserList as the PageName
  2. MyOrg-Data-User as the ObjClass as shown below

Note — Optionally, specify the maximum number of records to read in the MaxRecords field. If not specified, the system by default reads up to 10,000 records. Keep the number as low and realistic as possible for a good performance of the application. I’ve specified 10 as the MaxRecords below.

Obj-Browse

Important: Obj-Open reads all the properties of the record, including the system defined ones such as pxCreateDateTime, pxCreateOperator, pzInsKey, etc. Obj-Browse, on the other hand, reads only the specified properties of the records.

List the properties that you want to read from the data records as shown below. For each property to be read, tick adjacent the Select Field checkbox, and select Value Only option in the Condition dropdown list.

Obj-Browse

This completes the logic required in the activity to load multiple user records in memory.

Step# 3— Save and Run the activity

Save and run the activity as already explained above. If the code is correctly written, and there are no issues with the code, you would see the success message as shown below after running the activity.

Success Message

Step# 4 — Verification

Launch the clipboard tool to verify the results in memory. Switch over to the Standard thread, if required. Look for the UserList page in the left pane. Select it to review the pxResultCount.

Important — pxResultCount property indicates the count of records retrieved in the result set.

Since, I’ve three records in the data type, and I’ve retrieved all three of them in memory, the pxResultCount, in my case, is 3.

UserList clipboard page

Expand UserList node to drill down to the pxResults pagelist that holds the list of records.

Important — The system loads the records onto the pxResults pagelist under the UserList clipboard page. Each element of the pxResults represents or corresponds to a record retrieved from the data type.

Expand the pxResults node to review the elements of the pagelist. Since, the system has retrieved three records, the pxResults pagelist, in my case, has three elements, as shown below.

pxResults page list

Select the individual element of the pagelist to examine the corresponding data record as shown below.

Individual element of pxResults

--

--