CommunityCommons: Clone functionality

4
I am looking for a way to easily clone an object, meaning, to create a new object and fill its attributes with all the information of a retrieved object's attributes, without having to manually copy every attribute in a change action. I thought the 'Clone' java action that is included in the CommunityCommons module would let me do this. However, if I do the following: 1) Retrieve 'Contact' object 2) Create 'NewContact' object 3) Call Clone java action. Source = Contact, target = NewContact, withAssociations = false 4) Commit 'NewContact' The attributes of 'NewContact' remain empty. Am I doing something wrong, is this a bug, or is the Clone java not supposed to copy and fill attribute contents? Thanks,
asked
2 answers
2

You are right, I see a patched it already a while ago, but did not publish it yet. The quick fix for you is to open javasource/communitycommons/ORM.Java and change line 192

from

if (withAssociations || (((m instanceof MendixObjectReference) && !(m instanceof MendixObjectReferenceSet))))

to

if (withAssociations || ((!(m instanceof MendixObjectReference) && !(m instanceof MendixObjectReferenceSet))))

update

You are right, i missed that case in my test project. If you add those two lines before line 192 that issue is fixed as well. I will make sure those changes are embedded in the next release as well.

if (m.isVirtual())
    continue;
answered
0

Thanks Michel. That does indeed seem to work. I'm afraid there is still a problem though, in this case - I'm getting errors that seem to tell me something is going wrong when it tries to copy a virtual attribute (as far as I'm concerned, it can skip those, but...). Could that be right?

'com.mendix.core.CoreRuntimeException: A virtual primitive cannot be assigned a value, as it represents an action
    at iu.b(SourceFile:164)
    at com.mendix.core.Core.execute(SourceFile:187)
    at hg.a(SourceFile:70)
    at kW.a(SourceFile:66)
    at eO.executeAction(SourceFile:96)
    at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:49)
    at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:473)
    at iu.b(SourceFile:155)
    at com.mendix.core.Core.execute(SourceFile:187)
    at dx.execute(SourceFile:183)
    at jy.a(SourceFile:300)
    at jy.a(SourceFile:232)
    at jy.processRequest(SourceFile:183)
    at fA.a(SourceFile:75)
    at com.mendix.core.MxRuntime.processRequest(SourceFile:893)
    at com.mendix.m2ee.server.handler.RuntimeHandler.handle(RuntimeHandler.java:40)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
    at org.eclipse.jetty.server.Server.handle(Server.java:334)
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:559)
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1007)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:747)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:203)
    at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:406)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:462)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:436)
    at java.lang.Thread.run(Thread.java:619)

Caused by:
A virtual primitive cannot be assigned a value, as it represents an action
    at dN.setValue(SourceFile:260)
    at com.mendix.core.objectmanagement.member.MendixString.setValue(SourceFile:75)
    at com.mendix.core.objectmanagement.member.MendixString.parseValueFromString(SourceFile:58)
    at aL.setValue(SourceFile:274)
    at communitycommons.ORM.cloneObject(ORM.java:182)
    at communitycommons.actions.Clone.executeAction(Clone.java:43)
    at communitycommons.actions.Clone.executeAction(Clone.java:25)
    at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:49)
    at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:473)
    at iu.b(SourceFile:155)
    at com.mendix.core.Core.execute(SourceFile:187)
    at hg.a(SourceFile:70)
    at kW.a(SourceFile:66)
    at eO.executeAction(SourceFile:96)
    at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:49)
    at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:473)
    at iu.b(SourceFile:155)
    at com.mendix.core.Core.execute(SourceFile:187)
    at dx.execute(SourceFile:183)
    at jy.a(SourceFile:300)
    at jy.a(SourceFile:232)
    at jy.processRequest(SourceFile:183)
    at fA.a(SourceFile:75)
    at com.mendix.core.MxRuntime.processRequest(SourceFile:893)
    at com.mendix.m2ee.server.handler.RuntimeHandler.handle(RuntimeHandler.java:40)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
    at org.eclipse.jetty.server.Server.handle(Server.java:334)
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:559)
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1007)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:747)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:203)
    at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:406)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:462)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:436)
    at java.lang.Thread.run(Thread.java:619)
'
answered