Deleting duplicates in a list

0
Hello everybody,   I'm trying to delete all duplicates from a list but it seems that the Union list function is not working as it should be. Any ideas ?  
asked
2 answers
-1

In Mendix, the Union list function is designed to remove duplicates, but sometimes it may not behave as expected, especially if the items in the list are complex objects rather than simple values like strings or numbers. When dealing with lists of objects, Mendix checks for equality by comparing references (or object identities), not by comparing the actual content of the objects.

 

one approach is to manually check for duplicates by looping through the list and checking the properties of the objects.

  • Create an empty list to hold the distinct elements.
  • Loop over the original list and for each element:
  1. Check if that element (or a property of the element) already exists in the distinct list.
  2. If it doesn't exist, add the element to the distinct list.
  • After looping through the entire list, the new list will contain only distinct elements.
answered
0

You are doing the union in the loop and then discarding the results

You need to do the union after the loop and use the resulting list

answered