Discussion

Remove Duplicate values in Pagelist using same pagelist

I am fetching the values from internal data table.

I have a page list A.pxResults(100) which contains 100 embedded pages, in each embedded page has 10 properties with values

Now I need to  remove duplicates by comparing with all the 10 properties (AND condition applies for all these 10 properties) and these 10 property values are from the page list only...

Like first take A.pxResults(1) page and check in the complete page list of A... there after A.pxResults(2) and check inthe complete page list of A and if found any duplicate then delete it.

I gues I cannot use the functions IsInPagelist or RemoveDuplicatesFromList as i need to compare all the values of page list with the same pagelist and all the property values in the page should be same when compared before deleting.  

Please let me know the best apporach.

 

Regards,

Vinay

 

**Moderation Team has archived post**

This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Comments

Keep up to date on this post and subscribe to comments

July 16, 2015 - 1:54am

Hi Vinay

I assume your requirement as 

A.pxResults(1) has .Prop1 (Value ABC) .Prop2(Value XYZ) .Prop3(Value DEF)

A.pxResults(2) has .Prop1 (Value 123) .Prop2(Value XYZ) .Prop3(Value DEF)

A.pxResults(3) has .Prop1 (Value ABC) .Prop2(Value XYZ) .Prop3(Value DEF)

 

In this scenario, pxResults(1) and pxResults(3) are considered duplicates and not pxResults(2). If yes, you can try following approach:

Create another property Prop4 and set the value of concatenated from PROP 1 ,2 and 3 with any delimiter

Write a RD on PROP4 and select "Remove Duplicates". From that list, read the values based on delimiter into your page list.

 

Not sure if there is better approach, stage is open for other to comment

 

Vamshi

 

 

July 16, 2015 - 3:27am

My understanding of your requirement is -

Remove duplicates from pagelist. Two records in a pagelist are duplicate when all of the 10 properties have same value.

 

Java step can be used to remove duplicates if there is no other way -

ClipboardProperty pageListProp = myStepPage.getProperty("pageListName"); // read your pagelist property
HashSet<String> values = new HashSet<String>(); // declare a hash set
for(int i = pageListProp.size() ; i > 0 ; i--){ // iterate over pagelist
 ClipboardPage aPage = pageListProp.getPageValue(i);
 
 // read all 10 properties from aPage
 String prop1 = aPage.getProperty("prop1").getStringValue(); 
 String prop2 = aPage.getProperty("prop1").getStringValue();
 
 //concatinate all 10 properties in a string; separated by #
 String aValue = prop1 + "#" + prop2;
 
 // add concatinated string to set
 boolean isAdded = values.add(aValue);
 
 // if isAdded is false it means record is duplicate; so remove it from pagelist
 if(!isAdded){
  pageListProp.remove(i);
 }
}

July 16, 2015 - 3:51am

Hi Vinay, 

I dont think there is any easy way to achieve this.

You have to do it just like java codes.

You have to use 2 for loops and inside the inner for loop you have to use  when condition  to check it is duplicate

just like this 

for (i=0;i<=100;i++)

  for j=i+1;j<=100;j++)

   {

   Use when here ....

}

}

delete those which are duplicate.

 

* also one more thing why cant you check duplicate while entering in internal Data table (Hope data table have exactly 10 columns)

July 16, 2015 - 5:33am

Hi Vamshi,

In one way this will solve the problem with some more extra coding efforts, however we need to add one more column in the data table. 

Many thanks for the  quick response.

Regards,

Vinay

July 16, 2015 - 5:40am

Hi Ravi,

I think this is same as Vamshi's comment but on added benefit is we need not create a column in DT.

can you please eloborate the below steps as I dont see the duplicate check in the code... Apologies for ignorance, I am not perfect in Java coding and the below code is bit confusing.

1) What actually this does and what value we need to give in <string> place or its just a variable declaration.

HashSet<String> values = new HashSet<String>(); // declare a hash set

2)what actully this does?

boolean isAdded = values.add(aValue);

Appreciate the quick response, many thanks..

Regards,

Vinay

July 16, 2015 - 5:44am

Hi Prem,

can you be more specific regarding the for 2 inner for loops. I am unable to get any possible approach using for loops while fetching.

However the for loop approach will work better while inserting the records into DT and I will give a try with that approach.

Many thanks for the quick response.

Regards,

Vinay

July 16, 2015 - 5:52am

1) What actually this does and what value we need to give in <string> place or its just a variable declaration.

HashSet<String> values = new HashSet<String>(); // declare a hash set

This is just a variable declaration. We are declaring a set of strings which can store unique values.

 

2)what actully this does?

boolean isAdded = values.add(aValue);

HashSet.add() API is used to add an element into set. It returns true if it is succesful in adding the elements to the set(it means element you are adding is not present in the set).

It returns false, if it finds a duplicate entry in the set.

July 16, 2015 - 6:20am

we will be using 3 local values : start,start1,end

 

step 1: First step have a property-set for local variable

   say local.start = 1; local.end = 100; (declare all local variables as integer in parameter tab)

step 2.0: Open for loop

     Loop params :start = local.start; stop = local.end; increment=1

step 2.1: Property-set 

 local.start1 = local.start + 1;

step 2.2.0: Open second for loop

   Loop param : start = local.start1 ; stop = local.end; increment = 1;

step 2.2.1: check in pre-condition step. check for these 10 properties as 

when myPage.pxResults(local.start).property1==myPage.pxResults(local.start1).property1   .....continues when... check for till ...say property10.... if true continues when....... else jump to 2.2.3

step 2.2.2: Page-Remove

remove the other page which is duplicate.

step 2.2.3 : property-set

   local.start1=local.start1 + 1;

 

I think it will work. Give a try once.

 

     

July 16, 2015 - 6:25am

@Ravi-

Many thanks for the quick response.

I will try the approach.

I have another requirement as given below-

This is continuation to the above given scenario where if 5 specific property matches and the other 5 are not matching.

the 5 specific properties which may contain Organisation, Division, Unit, EMPID and Name and other 5 conatins some request parameters.

if the 5 values are same in the list with 50 records then we need to delete them in the A.pxResults and copy it into B.pxResults(which means in total of 100 records if the EMPID with 123456 has 50 records with different requests). Here the limit is 50 records, if it crosses 50 then its should delete the pages or mark something in the page and copy the entire list into another Pagelist and if it is less, then normal process should continue.

Any suggestions please.

 

Many thanks..!!

Regards,

Vinay

July 24, 2015 - 3:09am

I Got the solution for the above problem- I am doing this while fetching the records from data table.

September 14, 2015 - 1:40am

hey , we are saving so many page list in the WO while saving we need to do a duplicate check for all the pagelist - please advice is there any pega function to do this

September 16, 2015 - 7:14am

HI VinayY80,

 

You may also try below approach to remove duplicate pages in a PageList. For this we have to iterate pagelist inside the same pagelist.

say PageList - PoliciesList

Each page has 10 attributes. so add one more property on each page say 'IsDuplicate'

1. Start looping ForEachEmbeddedPage on 'PoliciesList' check pre-condition as 'IsDuplicate' is != 'No' and in first step set 'IsDuplicate' as 'No' and build a string all the properties seperating by a delimiter and set it to a Parameter.

2. start looping the same pagelist 'PoliciesList'  inside the iteration. Check Pre-Condtion as 'IsDuplicate' is NULL and compare the String of properties on this page with the main string from Outer Iteration and if they match set 'IsDuplicate' as 'Yes' on that page.

 

3. at the end of the Iteration you have value to 'IsDuplicate' on each page.

4. Use Obj-Sort and on the 'PoliciesList'  pagelist and remove pages with 'IsDuplicate' as 'Yes'

January 20, 2016 - 6:59am

We have function exists to remove duplicates from paglist

removeDuplicatesFromList 

February 5, 2016 - 8:20am

use pzGetUniqueListElements function

February 5, 2016 - 6:17pm

Hi VinayY80,

How is about the below approach?

Step 1. Loop for A.pxResults

Step1.1 : (Precondition) use IsInPageListWhen func to check the current pxResults(i) is present in a temp PageList (B.pxResults()) or not. If Not exists, Copy. If exists dont copy.

 

Once the execution is completed you will be getting the unique records in the temp page list.

 

N.B - This code is tried and executed successfully.

 

And regarding your next requirement do you have sample business requirement? So that it'll be easy understand why such implementation is required!!!!

 

Thanks,

Rajsekhar

November 16, 2016 - 6:22am

You can use below code to remove duplicates.

ClipboardPage DupPage= tools.findPage("DupPage");
if(DupPage!= null) {
pega_rules_utilities.pzRemoveDuplicatesFromListPage("DupPage","PropertyName");
}