Question
Accenture
US
Last activity: 17 Feb 2021 10:12 EST
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.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Coforge DPA
GB
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
Accenture
US
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.
Coforge DPA
GB
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
-
BAJARI Bajari
Accenture
US
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.
Accenture
US
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.
Welltok
IN
Yes,please do answer to @Bhavya_Incessant's question and also elaborate your requirement.
Accenture
US
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.
CGI
US
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.
Accenture
US
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://collaborate.pega.com/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.
CGI
US
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.
Accenture
US
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