How to compare the content of all fields of an object with another object based on fieldnames

0
For validation I need to compare the content of all fields of an object with another object that has the same field names. . Input is an Object and a member and I want to compare this with a field of another object with the same fieldname. Thanks!
asked
2 answers
0

Theo,

If it needs to be flexible you could create a list of field names of both entities (or retrieve them from MX Model Reflection). Then with the help of a little java, do a loop to retrieve the data from entity one and two and compare the data and then add the validation feedback.

This can also be done of course with microflows, just get the other entity record and add comparisons as a split to get the true or false.

answered
0

Something like this, where obj and obj2 are generic IMendixObjects passed in as parameters.

    String module = "TestModule";
    String entity = "TestEntity";
    Boolean includeVirtual = true, includeAssociations = true;
    IContext context = this.getContext();

    for(IMetaObject o: Core.getMetaObjects())
    {
        if(o.getName().equals(module + "." + entity))
        {
            for(IMetaPrimitive p: o.getMetaPrimitives())
            {
                if((!p.isVirtual() || includeVirtual) && (includeAssociations || !(p instanceof MendixObjectReference || p instanceof MendixObjectReferenceSet)))
                {
                    if (!obj.getValue(context, p.getName()).equals(obj2.getValue(context, p.getName()))))
                        return false;
                }
            }
            break;
        }
    } return true;

Edit: Small error in first post.Corrected and should work now.

answered