sub NanoFlow changes

0
Hi everyone   on the docs page: https://docs.mendix.com/refguide/microflows-and-nanoflows/#differences   the last sentance says: "Changes done to the lists in a sub-nanoflow are not reflected in the original nanoflow."   does this mean that if i pass a 'User' to a sub, and in the sub retrieve the users "events" and set them all to done, that this will not be saved one I leave the sub?   is it only lists? is it when retrieving a list inside a NF or only when passing a list through?
asked
2 answers
1

This only affects passing a list to a sub nanoflow and making changes to that list like adding or removing items. The sub nanoflow gets a copy of that list, not a pointer to the list in the calling nanoflow so the calling nanoflow does not 'see' any changes made by the subflow. Changing objects in the list and committing the list is not affected and works the same as always.

answered
0

This is how I understand it. The sentence in the docs is not about objects disappearing or changes being lost. It’s about how list variables behave in nanoflows. What it really means is that if you change a list inside a sub-nanoflow, those list changes are not automatically reflected back in the parent nanoflow.

 

For example, imagine you have a main nanoflow where you get a User and retrieve their Events as a list. You pass that list into a sub-nanoflow. Inside the sub, if you remove some events from the list, add new ones, or filter the list and reassign it, when you return to the main nanoflow the original list is still the same. That’s because lists are passed as a copy, not as a reference.

 

Now, in the example you mentioned, the behavior is different. If inside the sub-nanoflow you retrieve the user’s events again and set Done = true on each event, those changes do not disappear. In that case you are not changing the list itself, you are changing attributes on persistent objects. The list is just a way to loop over those objects. As long as the objects are committed via a microflow, the changes are saved.

 

Another way to look at it is this. If in a sub-nanoflow you take an events list and remove the first item from the list, the main nanoflow will still see that event in its list. But if in the same sub-nanoflow you change an event’s status to Completed and commit it, when you go back to the main nanoflow that event will show as Completed.

 

So in short, the sentence in the docs is saying that list contents are not synchronized between parent and sub nanoflows. It is not saying that changes you make to objects are lost. Lists behave like value types in nanoflows, but the persistent objects inside those lists can still be saved to the database through a microflow.

answered