How to Remove Items from a Page List in a Data Transform

There are three main approaches to removing elements from a Page list based on specific values

Approach 1: Using For Each Page In with Remove Action
This approach iterates through each page in the list and removes items that match your criteria:

  1. Create or open your Data Transform rule.
  2. Add a For Each Page In action.
  3. Add a When condition inside the For Each action.
  4. Inside the condition, set the .pyDeletedObject to true.
  5. Call the @RemoveDeletedObject(MyPageList) outside the For Each loop

Note: .OperatorList is a Page List ​

Approach 2: Creating a New Filtered List (I know this not a ‘remove’, but the result is a list without the items you wanna remove)
This approach creates a new list with only the items you want to keep:

  1. Create or open your Data Transform rule.
  2. Add a For Each Page In action.
  3. Add a When condition inside the For Each action.
  4. Inside the condition, set the current page to a new page list.

Variation: Filter Results Directly on the Source
One variation is to filter the results directly on the source:

  1. Select the action Append to.
  2. Fill the empty list target and set the relation to each page in.
  3. Click the small icon and fill the popup Conditionally Append Source to filter directly in the origin.

Approach 3: Using the Remove Action Directly (For Simple Cases)
For more straightforward scenarios where you know the exact index of the item to remove:

NOTE: This operation removes a single page from the page list, precisely the page at the last index where the specified condition is met within the loop.

  1. Create or open your Data Transform rule.
  2. Add a For Each Page In action.
  3. Add a When condition inside the For Each action.
  4. Set a parameter with the index to remove inside the condition.
  5. Outside the For Each loop, select the remove action and set the target to the list index.

References:
Pegasystems Documentation
Pegasystems Documentation
https://academy.pega.com/topic/data-management

@tavelApproach 3: This will delete only one page from the page list when the condition matches at the end of the loop, and the last index will be used.

@Arunkum@r

You’re absolutely right. My initial explanation was too general. It only removes a single page at the last index where the condition is satisfied.

I will revise the text accordingly.

Thank you for the correction.

If I remember correctly, we can’t directly use “Remove” inside a “For Each Page In” right? It would cause issues

@RobertM17829543

Using Remove directly inside a For Each Page In loop on a Page List within a Data Transform is technically possible, but it’s risky and not recommended.

Since a Page List is ordered by numbered subscripts (.PageList(1), .PageList(2), etc), removing an item while the loop is actively iterating forward causes every subsequent item to shift down by one position immediately.

The loop, however, keeps advancing its own internal counter forward regardless of that shift.

So if you remove the page at index n, the item that used to sit at n+1 slides into position n, but the loop has already moved on to check index n+1, meaning it silently skips the item that’s now sitting at n.

In practice this means a “Remove” fired on every matching iteration will end up leaving some matching items untouched. In more extreme cases, particularly with larger lists or nested loops, this shifting can even trigger “Index Out of Bounds” behavior.