How to remove index in a page list inside a page list with a duplicate

I have an example page list of:

.Documents(1).Signatories(1).pyEmail = “abc”

.Documents(1).Signatories(2).pyEmail = “xyz”

.Documents(1).Signatories(3).pyEmail = “abc”

.Documents(1).Signatories(4).pyEmail = “jkl”

Since .Documents(1).Signatories(1).pyEmail and .Documents(1).Signatories(3).pyEmail have the same value,

I only need to retain .Documents(1).Signatories(1).pyEmail and remove the index .Signatories(3) from .Documents(1)

However, when I do: @Utilities.pyRemoveDuplicatesFromPagelist(pyWorkPage,“.Documents(Param.Index).Signatories”,“.pyEmail”)

I’m getting an error:

Test compilation failed: ----------

  1. ERROR in /Rule_Obj_Model_REDACTED.java (at line 440)
    pzSourceVar38 = pega.resolveMethodCall(“pyRemoveDuplicatesFromPagelist–(ClipboardPage,String,String)”, “pyRemoveDuplicatesFromPagelist”, null, “Utilities”, new Object { pega.findPage(“pyWorkPage”, “REDACTED-CLASS”), “.Documents(Param.Index).Signatories”, “.pyEmail” });

Is there a better way to approach this? Thanks!

Hi @miecaelagarcia ,

Please try to use the function pyRemoveDuplicatesFromPagelist inorder to remove the duplicate.

@miecaelagarcia

Copy data from .Documents(1).Signatories(1).pyEmail to TempPage.pxResults(1).pyEmail

and then use the function @Utilities.pyRemoveDuplicatesFromPagelist(TempPage,“pxResults”,“pyEmail”)

@Kishore Kumar Madduri

Thanks for the suggestion! Unfortunately, this still doesn’t work for me.

I have set TempPage to Code-Pega-List, and the pxResults to the class of Signatories.

There is no error, but it is still not removing the duplicates.

@miecaelagarcia

I have tested the solution above, which involves using a temporary page list to perform duplicate removal, and it works for me.

@Utilities.pyRemoveDuplicatesFromPagelist(RemoveDuplicates, “pxResults”, “ppyEmail”)

Could you try trimming the pyEmail property (using @String.trim) while creating the temporary page list? This will ensure there are no extra spaces that could cause the duplicate search to fail.

By the way, this approach only worked for me when using a temporary page list—see the attachments below.

Hi @miecaelagarcia

The issue might be with the expression you’re using. Try this instead:

@Utilities.pyRemoveDuplicatesFromPagelist(TempPage, “pxResults”, “.pyEmail”)

please ensure pxResults is a valid page list, and .pyEmail has trimmed, lowercase values to catch true duplicates

@miecaelagarcia

In this case you are removing the duplicates in TempPage not on the original page, you need to map the TempPage details back to same index of the original page.

@miecaelagarcia

To remove duplicate emails from a nested page list like .Documents().Signatories(), you cannot directly use pyRemoveDuplicatesFromPagelist because it doesn’t support nested lists or dynamic index references. Instead, you can create a simple Activity or Data Transform. Loop through each item in .Documents(), and for each document, loop through the .Signatories() list. Create a temporary list to store emails you’ve already seen. As you go through each signatory, check if the email already exists in the temp list. If it does, remove that signatory from the list. If not, add the email to the temp list. This way, you can keep only the first occurrence and remove the duplicates cleanly.

@RusselK1

The issue that I see in this kind of testing is that we are only explicitly removing the duplicates in the signatories of Documents(1) that is why it is working, and it will indeed work.

What we need to do is also loop through all of the indexes of Documents, so all the duplicates of all the signatories per Documents index are also removed.

That was why I added (Param.Index) in @Utilities.pyRemoveDuplicatesFromPagelist(pyWorkPage,“.Documents(Param.Index).Signatories”,“.pyEmail”) in my question above

@miecaelagarcia

Have you declared index as integer?

If yes, I think the pyRemoveDuplicatesFromPagelist function does not recognize the parameter passed

I would recommend to leverage on the index to in a For each page in loop which set RemoveDuplicates.pxResults to Documents().Signatories

You would append back Documents().Signatories from RemoveDuplicates.pxResults for each page

Could you try this?