Should I give an object back to the major mf or not?

0
hi guys,   in order to understand Mx more I am wondering what  the "official" way is of giving an object back to the MF from a subMF.   For example: I store the aggregated info in a object, called Info. And I have 5 different subMF's wherein I count, which needs to store the aggregated integers in that object. So I can give each time this Info object as a parameter to the submf AND submf could give it back as an updated Info" object at the end. The next sub MF could use for its parameter the Info" object and so on... OR The same without giving the object back at the end's of the subMF to the major MF.   I think the both are doing what it should.   But which is better and why?    
asked
3 answers
2

As you stated, both should work. I believe the proper choice is to not return the object as it makes you have to manage multiple objects within your microflow. 

answered
2

Enzo,

In a microflow, you can retrieve the same object multiple times.  Mendix 'knows' this is the same object. If you inspect the objects via debug, you'll see they have the same id.  

If you want to know if two Microflow objects point to the same object in the database, you can simply compare them in an expression such as:  

$Object_Copy1 = $Object_Copy2

This expression will evaluate to true if both Microflow objects point to a database object with the same id and it will evaluate to false if these Microflow objects point to different database objects.

If your submicroflows are updating different fields on the same object, I think the best approach for the question you posed is to not pass the objects back at the end of the microflow.  You already have the object in your 'parent' microflow, and passing it back will incur additional processing cost by requiring that object to be

  • Passed between microflows and
  • Compared in the parent microflow to ensure you have the correct object

 

Hope that helps,

Mike

answered
1

I think it all depends on what you want to do in the submicroflow. When I want to retrieve an object that might not exist yet I always use a submicroflow that does the retrieve by either giving back the retrieved object of when no object is found creating a new object and returning that one. This way you do not have the problem in your main microflow that you have two names $object or $newobject depending on the situation.
From a logic standpoint it is sometimes better to return the object and I always use then updated in the name of the return object. This makes following the logic of a microflow sometimes better, because you are not always aware that an object is changed in a submicroflow.

So I do not think their is a 'best' way. It all depends on what you are achieving and on how complex the microflows are.

My two cents on this subject.

Regards,

Ronald

 

answered