Copy objects from one entity to another entity

1
Hello, I have an entity called Tenders with five attributes called PublicatieId of type Integer which is also key, AanbestedingNaam of type string, AanbestedendeDienstNaam of type string, Europees of type boolean, Kwalificatie of type boolean. I also have another entity called Bids with the same five attributes called PublicatieId of type Integer which is also key, AanbestedingNaam of type string, AanbestedendeDienstNaam of type string, Europees of type boolean, Kwalificatie of type boolean and bunch of other attributes.   So these two entities share the same five attributes. I have an attribute called Kwalificatie of type boolean and when a particular object is loaded you have the choice to press a button called ‘Kwalificatie’.   When this button is pushed by the user, I would like to set 2 actions in motion (via microflow I presume); 1) I would like to change the value of the boolean ‘Kwalificatie to ‘true’ and 2) I would like to copy or clone the object from the entity Tenders to the entity Bids.   I have read about the module called ‘clone’ and also about the module ‘deepclone’, but I just don’t know what to do exactly.   The problem is that I'm quite new in Mendix and I don't know how I can fix this. I would really like some help to solve this problem. Any help is greatly appreciated, thank you!  
asked
4 answers
3

Clone and Deepclone can be found in the community commons module from the appstore. But you should be carefull with them, because they can also take care of associations and that can lead to unexpected behavior.

If you only want to copy attributes, you can also find a java action called copyAttributes. It is doing what you need. It copies attributes with the same name from one object to another. It does not need to be the same entity.

answered
0

Thank you for your advice to be careful about Clone and Deepclone.

I have tried to work it out with copyAttribute, but I just can't get it to work and I'm not sure how to solve this.

I have created the Microflow ‘PrequalifyTender’ which gets activated when pressed on a button called ‘Kwalificatie’.

I have created 3 activities in the Microflow: the first one is to change the Attribute ‘Kwalificatie’ of type boolean in entity Tenders to true and this doesn't give an error. The third and final activity is a commit and this doesn't give me an error right now. 

The second activity however is the activity copyAttributes and this gives an errorcode CE0126 with the message ‘missing value’ and Mendix doesn't proceed because of the error:

Parameter ‘Parameter’ of action activities ‘Copy object attribute contents’. 

I will attach a screenshot of the Microflow below.

 

I have searched on the Net, but I can't find a solution; can you help me out?

answered
0

I have removed copyAttributes and now my project is producing errors and won't compile.

The errors that I receive is this:

 

    [javac] C:\Users\xxxx.xxxx\Documents\Mendix\Bidkwalificatie-EXPERIMENTAL-v2\javasource\objecthandling\actions\copyAttributes.java:42: error: cannot find symbol
    [javac]         ORM.copyAttributes(getContext(), source, target);
    [javac]                                          ^
    [javac]   symbol:   variable source
    [javac]   location: class copyAttributes
    [javac] C:\Users\xxxx.xxxx\Documents\Mendix\Bidkwalificatie-EXPERIMENTAL-v2\javasource\objecthandling\actions\copyAttributes.java:42: error: cannot find symbol
    [javac]         ORM.copyAttributes(getContext(), source, target);
    [javac]                                                  ^
    [javac]   symbol:   variable target
    [javac]   location: class copyAttributes
    [javac] C:\Users\xxxx.xxxx\Documents\Mendix\Bidkwalificatie-EXPERIMENTAL-v2\javasource\objecthandling\actions\copyAttributes.java:43: error: incompatible types: boolean cannot be converted to IMendixObject
    [javac]         return true;
    [javac]                ^
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] 3 errors

 

I have removed the App Store module copyAttributes and I have redownloaded the module Community Commons Function Library and I have chosen to replace the existing module, but it didn't help.

 

Can you please help me out to fix this?

answered
0

I have removed the module copyAttributes. I have reinstalled the Commons Commons App, but it doesn't restore the copyAttributes module since I can't select it in an activity. I have also tried to restart Mendix Studio Pro, but that doesn't help. The three questions I have are : 1) What can I do to get copyAttributes back? 2) Can somebody please give me some (detailed) help how to use the copyAttributes module in order for me to copy attributes? 3)Is there perhaps an alternative way to copy attributes from one entity to another entity in Mendix 8.8.2?

 

Thank you for helping me out!

answered