Question

Looping through pxResults

I need to loop over search results and find something in those results and create another pagelist if my results contain something I am looking for.

.

As shown in my picture, I need to loop over the pxResults of class Data-Find-Results and if I find the keyword 'Spanish' in either pxInsName or pzInsKey of the property, I need to create another pagelist of class Data-Find-Results and populate that new pagelist with pxResults(9).

Can someone show me how to do this preferably with a diagram.

Correct Answer
June 13, 2019 - 10:14am

I followed the instructions sent by CGIC7768 and it can be accomplished this way

 

Comments

Keep up to date on this post and subscribe to comments

June 11, 2019 - 11:46pm

Hi

A quick  question, can your pagelist contain multiple instances for same keyword?

I mean for key Spanish can you have pxResults(6) and pxResults(7). Looking at the diagram I dont think it should be, but still can you confirm?

Regards

Bhavya

June 12, 2019 - 9:29am
Response to Bhavya_Incessant

The key word would not be found multiple times. One single iteration over the pagelist should be good. I need to know how I can get a 'handle' on the pagelist to iterate over it and then compare and then populate another pagelist.

June 12, 2019 - 10:01am
Response to ChakriP8

Hi

If that is the case, then use the function "Indexinpagelist" with necessary parameters to get the index. No need to iterate over all records.

Once you get the index, use that to copy that instance to another pagelist. You can do a Property-Set, and copy necessary properties.

Hope this helps.

Regards

Bhavya

June 12, 2019 - 10:18am
Response to Bhavya_Incessant

Bhavya,

Can you please 'show me' as I am new to pega. I am not looking for a single instance.

The word Spanish can be found multiple times, say at index 6 or at index 211. Because two instances are found, I need to create a new pagelist and copy over the result set at 6 and 211. So my new pagelist will be of length two and will have the records pxResult(6) and pxResults(211) of the original pySearchResults pagelist. Can you please paste a picture of your activity. 

June 12, 2019 - 10:27am
Response to ChakriP8

I misunderstood your question. The keyword Spanish could be found multiple times in the pagelist. So I would need to iterate over the whole list. Can you please 'show' me with a picture how I can grab a handle on the pxResults pagelist and the iteration over it. I am not sure how to use 'for each embedded' in the activity I am creating to loop.

June 12, 2019 - 3:23am

Yes,please do answer to @Bhavya_Incessant's question and also elaborate your requirement.
 

June 12, 2019 - 9:38am
Response to VinayK29

My requirement is to loop or iterate over pxResults .... while iterating I need to compare/check for text a property .... populate another list (same type) when comparison is true.

 

June 12, 2019 - 5:45pm

In the pic you posted, the pxResults is an inner list of pySearchResults.

To get a handle on the pxResults, you will need to declare the classes in your Pages & Classes of your Activity

In your Activity, choose Loop and 'For Each Embdded List' and then right click to add a child. In the StepPage you can loop through pySearchResults.pxResults as shown below.

June 12, 2019 - 11:49pm
Response to CGIC7768

Thanks for posting the pics and giving such a beautiful explanation! It worked. I am able to loop through pySearchResults.pxResults(). However I need to populate the SearchQRPage Pagelist with the exact same data at index 6 and index 211 i.e. copy the values over from pySearchResults to SearchQRPage.

When my When condition is true, I need to add to SearchQRPage the pxResults of pySearchResults.pxResults(6) and pySearchResults.pxResults(211),  so that the size/length of my SearchQRPage Pagelist is now 2. 

My requirement is exactly like this - https://community1.pega.com/community/pega-support/question/copy-values-one-page-list-another-page-list

Can some one show me how  I can 'ADD' to SearchQRPage in an activity - screen shots of the code and the steps would be helpful.

June 13, 2019 - 10:14am

I followed the instructions sent by CGIC7768 and it can be accomplished this way

 

June 19, 2019 - 12:58pm

I noticed that you were working on pxResults of class Data-Find-Results which is the class for OOTB search. This class has 'hidden' properties if you need to load them. You can do this as shown.

June 20, 2019 - 1:52pm

I found this site extremely useful for looping and the keywords - <current>, <insert> and <last> and also Param.pyForEachCount for PageLists, .pxSubscript for PageGroup.

http://myknowpega.com/2017/07/24/aggregate-properties-indexes/

Also understood Dynamic Class Referencing property of pxResults using $CLASS and $ANY