Hi Thijs,
To the best of my knowledge there is no such function in the community commons. But it should be fairly straightforward to write it yourself.
In java you can get all the attributes and associations (in java "members") of an object and iterate over them in a loop. Maybe something in the lines of
for ( String member_name : object1.getMembers(context).keySet )
if ( object2.getValue(context, member_name)!= null )
object1.setValue(context, member_name, object2.getValue(context, member_name));
You can also look at how the community commons module does it here - https://github.com/mendix/CommunityCommons/blob/master/src/CommunityCommons/javasource/communitycommons/ORM.java
Hope this helps,
Andrej
Thanks Andrej,
I indeed re-used the code from the Community Commons 'CloneObject' action, so that you can also exclude associations if you'd like.
IContext context = this.getContext();
// Should be improved by only iterating over the members that you want to clone
// (not an instance of MendixObjectReference/MendixObjectReferenceSet, not an autonumber, m.GetValue != null and m.getValue != "" )
Map<String, ? extends IMendixObjectMember<?>> members = Source.getMembers(context);
for(String key : members.keySet()) {
IMendixObjectMember<?> m = members.get(key);
if (m.isVirtual())
continue;
if (m instanceof MendixAutoNumber)
continue;
if (WithAssociations || ((!(m instanceof MendixObjectReference) && !(m instanceof MendixObjectReferenceSet)&& !(m instanceof MendixAutoNumber))))
if (m.getValue(context) != null && m.getValue(context) != "")
Target.setValue(context, key, m.getValue(context));
}