In this example, the implementation for iterating over a Page List in Pega 7 Data Transform is described. A data page that uses a Page List structure is used as an example. See this example on how to create a data page using the Data Table Wizard. The page list data page is backed by a data table of car makes and is used here to show how to iterate over its entries in a data transform.
Related Posts
- Sort Dropdown Options with Data Transform in Pega 7.1.9
- Group Dropdown Options with Data Transform in Pega 7.1.9
- Example of Cascading Drop Downs in Pega 7
- Pega 7 String Manipulation with Expressions and Functions
Summary
- Description of Data Table for Class ABC-Insurance-Data-Make Used in this Example
- List Data Page for ABC-Insurance-Data-Make Rule Instances
- Creating a Data Transform for Iterating over the Data Page
1 Data Table for Class ABC-Insurance-Data-Make
- The screen shot below shows an example of a Data Table. In this case, the rows represent car makes. See the link under Related Posts on how the data table was created.
- The data table contains instances of the class
ABC-Insurance-Data-Make
. This class has the propertiesID
(Integer) andpyLabel
(Text). - The
ID
is a unique identifier (Key) and thepyLabel
property contains the actual car make values.
2 List Data Page for ABC-Insurance-Data-Make Rule Instances
- The below screen shot shows the configuration of a list-structure data page named
D_Makes
. Its purpose is to store a list of car makes. The Data Page Definition section is configured as follows:
Structure:
list
Object Type:
ABC-Insurance-Data-Make
Scope:
Node
Data Source:
Report Definition
- Node scope causes the data page to be available to all users on a node (i.e. it will be loaded once per PRPC node).
- The Data Table Wizard creates a default Report Definition. Here it is named
dataTableListReport
and it returns all rows in the underlying data table.
- The data page can be unit tested by clicking on Actions > Run.
- The XML of the data page will be shown and the node
pxResults
(a PageList) will contain all of the rows in the data table.
- After running the data page once, it will appear in the Clipboard Tool under Data Pages > Node.
- Due to its Node scope, the data page
D_Makes
will remain on the clipboard until the PRPC instance is restarted or the data page is deleted using the Designer Studio or the Clipboard Tool is used to delete it (see the Actions button in upper right-hand corner).
3 Creating a new Data Transform for Iterating over the Data Page
- In Designer Studio, create a data transform using +Create > Data Model > Data Transform.
- The Data Transform Record Configuration form requires the user to enter a name, here it is
IterateOverMakes
and to select an Apply to class. Here, the class isABC-Insurance-Data-Make
. - Click on the Create and open button to create the data transform rule.
- On the Parameters tab, an output parameter named
MakeString
of data type String is defined. - It will be used to return a comma-separated String of car makes that is created by the data transform while it iterates over the data page
D_Makes
.
- On the Pages & Classes tab, the data page
D_Makes
needs to be listed with a class ofCode-Pega-List
. - The class
Code-Pega-List
has a page list property namedpxResults
which holds instances of the object type specified when the data page was configured. Here the object type isABC-Insurance-Data-Make
. - Specify the class of
D_Makes.pxResults
as shown below.
- On the Definition tab, the first row will use the action For Each Page In to iterate over the
D_Makes.pxResults
page list. - The checkbox
Also use each page as source context
in the Source column should be checked so that the.
dot operator can be used to refer directly to the current page of the iteration instead of having to useD_Makes.pxResults(<CURRENT>)
. - In the second row,
param.MakeString
is concatenated with thepyLabel
property of the currentABC-Insurance-Auto-Make
instance. - The third row uses a simple expression to remove the last comma in the comma-separated string after the iteration. The complete expression is:
@(Pega-RULES:String).substring(param.MakeString,0,@(Pega-RULES:String).length(param.MakeString)-1)
- Save the data transform and open the Tracer. Make sure that the check boxes for Start and End for data transforms under the section Events to Trace are checked.
- The data transform can be unit tested by selecting Actions > Run and then clicking on the Execute button in the new window. Note: Make sure that the Tracer is running before executing the data transform.
- A new window opens and shows XML output from executing the data transform. The
pzStatus
will contain the valuevalid
if the exeution was successful.
- Switch to the Tracer window and search for the row where the event type shows Data Transform End and click on that row.
- A new window opens, showing the properties of the test page that was created for running the data transform. Click on the link
=unnamed=
link of the Parameter Page Name property in theTraceEvent[8]
page.
- This will open the
TraceEvent[=unnamed=]
page, showing the output parameter namedMakeString
which was set by concatenating the car make values while iterating over the data pageD_Makes
to generate a comma-separated String value of the car makes. - The page also shows some Pega out-of-the-box properties, prefixed with
py
orpz
. - In the below screen shot, a property named
pyForEachCount
with a value of8
is shown. This is the number of iterations that were executed by the For Each Page In data transform action (i.e. the number of items in the D_Makes.pxResults list).
- Note: The tracer also shows that
Code-Pega-List
maintains the order of the entries in the data table. - Pega is implemented in Java and the underlying Java interface- and implementation classes for
Code-Pega-List
are java.util.List and java.util.ArrayList from thejava.util
package.
3 thoughts on “Iterating over a Page List in Pega 7 Data Transform”