Comparing two objects

Hi all, I need to compare two objects in a microflow. There are two productparts associated with a producthead. There is a one to many relationship (One ProductHead can have many ProductParts) I need check, if both productparts are the same. Any suggestions?
4 answers


As Eric said, you can compare two objects with an equal sign - this is equivalent to comparing the GUID's for the two objects by use of the Java action.

From your question, seems like you might be trying to identify duplicate parts, so I'll use this as an example:

  • Retrieve all productparts associated with a given producthead, lets call it AllParts
  • Create an empty list of product parts which you'll use to build your unique list, I'll call this one UniqueParts
  • Iterate over AllParts in a loop in your microflow
  • In the loop, use List Operation find to see if IteratorAllParts is already in UniqueParts list
  • if its not in UniqueParts, add it
  • if it is, go to the next iteration

When you come out of your loop, you'll have a list of unique parts that you can use as you need to.

You could have a retrieve action in the loop with an xpath that looks like [id=$iteratorAllParts] which would retrieve the current loop object and store it in a variable you could use to do a comparison in the next loop. However, that would be useful if you were able to sort the parts list by an attribute like part number.

Hope that helps,



For your actual question: you could retrieve all objects, then for each objects, compare it to all other objects to see if they are equal on the set of attributes that define uniqueness (e.g. $Object1/Name = $Object2/Name and $Object1/ProductionCode = $Object2/ProductionCode). If they are duplicates, put one of the in a list and do something for this list.

To solve your general problem though: I question if you have modeled correctly: the relationship between ProductHead and ProductPart sounds like it should be a many to many relationship, since ProductParts sounds like something that could be used in many ProductHeads. If so, then this problem could be deferred to saving a ProductPart: when saving a part, retrieve a ProductPart with a different id than the current object, but equal on the set of attributes that define uniqueness. If it exists, simply do not save.


Retrieve the two lists of ProductParts over association of the 2 ProductHeads. Compare the lists with list list operation "equals". If the ProductParts are not the same objects (as Rom wrote) but created per ProductPart use a unique key :

  1. Create variable $same default "true"
  2. Length of the 2 lists not the same: $same = false
  3. Loop thru list one and use list operation find on the key in list 2 : if not found then $same = false break loop.

Would they be the same exact object? If so, I think you can use equality in an expression to test this:

$Item1 = $Item2

If that doesn't work, there's a CommunityCommons java action to get an object's internal Mendix id: CommunityCommons.getGuid. You could directly compare those 2 values for equality.