Deleting collection entity members can be tricky, especially when the delete logic is referring to the same collection in aggregate. The key is to break the logic into two steps, logic to set a delete flag and a process to perform the delete.
Two approaches to delete are:
- Delete the members using the Remove Collection Member Action
- Somewhat cumbersome because Remove Collection Member Action requires a loop at the parent level.
- Make a copy of the collection using the Copy Collection Action that filters the collection to only the members you want to keep
- Most simple and flexible approach, because it does not require a loop (will eliminate the entire Process loop in screenshot below)
- Simple aggregate logic can go directly into the filter expression, but for complex logic better to pre-process using Execute Member Rule Set to set a delete flag to filter on
If you have to physically delete from the source collection using option 1 (as compared to creating the filtered copy), here’s an example of the two step process. For simplicity, I’m keeping the logic to a simple equality check:
- The FlagLiabilityForRemoval ruleset is run for each member and uses the Count function to set the DeleteFlag (note the check to ensure the member has not already been flagged for removal)
- Note the check to ensure the member has not already been flagged for removal (cut-off in screenshot, entire expression should be):
Count(Liabilities, PaymentAmount = CurrentContext(PaymentAmount) and DeleteFlag <> true and CurrentContext(DeleteFlag <> true)) > 1
- If the logic is too complex to go into a single aggregate function, then another parameterized Execute Member RuleSet can be used to pass in the calling collection member. This is a common approach for a many-to-many comparison.