How to save a Page List into data type, Pega Tutorials

 Hi All, recently I had some troubles saving a list into a data type, that is something that I have never done before and there is so little information about it in the pega community sites, so let's get this done 

to start you have to create a data type and have records on in, if you don't know how to do that, you can watch this video explaining step by step how to create a data type https://youtu.be/rYex_UsTtMg .

The next thing that you will need is a page list property, when you are creating the page list property in page definition you have to add the class of the data type. 



Once we create the page list the easy way to add records to it is through a table so on your section you can configure a table

to configure a table select property on general than in order to add data, on table settings click on Operations and in row editing select inline and then click the row to edit and submit  





save the section and test by adding some data to it, you will get something like this :


You can check your list on the clipboard:




Now that we have the list the next step will save it into the data type, I had some struggle at the beginning because i tried to do the logic in the data page, for some cases is very useful to map the data using a response data transform that is good when you have a to map values one to one, in this case, i will solve using and activity outside the data page, this activity you can call it from a button, flow action, utility shape in the flow where ever you need it according to your logic, for this example i will use it on a button

The first step to creating the activity is to analyze the list that you are trying to save, to define the loops 
that is very important because sometimes we have a page list inside a page 

I will explain the creation by steps into the activity  

Step 1

On the step one we click on Loop then we select the option "for each embedded page" leave the class empty and then click on submit. then on the step page we put the page list property where we want to make the loop 
 



step 1.1

We create a new page, Whe use the method page new to do it and this is very imoportant and the reason that i almost loose my head, because i only get to save the first record of the list and it was because i missed this step, every time that we make a loop we need a new page to save the record otherwise you will be overwriting the data.  so in pages an clases tab we define the class of the data type, then on the step page we use the page that you saved 


Step 1.2

on this step we do a maping of the data that we want to save using the method Property-set 
since we are on the context of the customerList porpery we need to reference the properties from the data type

Step 1.3

On this step we use an object save and on the step page the page for our data taype class, it will save every iteration of our list and that will be the last step 

so tour activity should look like this 


Lest try it 

now i called from a button and when we run it all the proceses in the backgorund when we trace the activity looks like this: for each page list it will save the values 



Troubleshooting 

if by any Chance you encounter problems and it not saves, check this 

The Key of the page, open the class of your data type and if the key is not auto generated you will have to pass the key in order to save a new input, you can create a unique ID using  this function if you need it CreateUniqueID() 

If you still have issues saving, please check on the obj-save step expand it and check write now checkbox

if you are not able to get this to work please comment and i will help you, Hope it works for you:)










Comments

Post a Comment

Popular posts from this blog

How to create a case type and data model in pega 8.5 | creating an application

DOWNLOAD PEGA PERSONAL EDITION FOR FREE