Function to get unique records count In page list

Hello,

I have a requirement where I need to get the count in page list when a condition is satisfied and the counted pages are unique by one property.

I know we have a function called countInPageListWhen already, But this will give me only the count in page list when a condition is satisfied. I need to also validate the record is unique by a property.

So I need Java code to create a function for this requirement. My function syntax should look like below.

@getUniqueCountWhen(whenRule, uniqueProp, pageList).

Thanks in advance :slight_smile:

@RameshBattini

I think the easiest way is to use this OOTB function to first remove duplicates based on a property in the page list.

@pyRemoveDuplicatesFromPagelist(ListPage,“.pxResults”,“.uniqueProp”)

And then apply the countInPageListWhen() to the page list with the duplicates removed.

However, this will modify the input pagelist, so if you want to keep the input unchanged, then apply the function on a copy of the original pagelist.

@JoeH9464 hey,

Thank you for your response

I can’t go in that direction because as you said I want to hold the original pagelist always and also I have to use the function in declare expression, Otherwise I would have done this already :slight_smile:

@RameshBattini

You can encapsulate the same process from above in a java function like this

Inputs

String whenName;
ClipboardPage listPage;
String pageListPropertyName;
String uniqueProp;

Output

int (Number)

java

ClipboardPage tempListPage = listPage.copy();

pega_rules_utilities.pyRemoveDuplicatesFromPagelist(tempListPage,pageListPropertyName, uniqueProp);

int count = pega_rules_utilities.countInPageListWhen(whenName, tempListPage.getProperty(pageListPropertyName));

tempListPage.removeFromClipboard();

return count;

Example of calling it

@DistinctCountInPageListWhen(“YourWhenRule”, SourcePageList, “.pxResults”, “.UniqueProperty”)

@JoeH9464 Hello, Good day!

It worked, Thank you for the quick response <3