Passing list as Action parameter at Server it is pass by reference at Mobile as value

Passing list as Action parameter at Server it is pass by reference at Mobile as value

  

I'm pretty new with OutSystems platform, but I think this is really weird behavior or even bug. 

So on on Web when I have Server Action and I pass List containing structure as parameter it is passed as reference, but if I do same at Mobile with Client Action it is passed as value - I'm thinking WTF

I did found some other differences also, but this I don't understand why?

Could it be fixed?

Hi Sampsa,

This seems to be by design, and not a bug. This is a snippet of the javascript code generated by the platform for a Client Action that receives a List as an input parameter and adds some elements to it:

As you can see, a local clone of the input parameter is created and it is this clone that is manipulated. As a result, the original list that you passed into the action will remain unchanged.

Hi Sampsa,

First, this behaviour has nothing to do with the List containing a Structure, Lists of simple types should behave the same. Secondly, whether Lists are passed by reference or not depends on a lot of factors. On Web, a List is passed by reference if the Action called is in the same eSpace or in an Extension, and there is no conversion (implicitly or explicitly by mapping). Otherwise a copy is made. This is all very unclear, and imho OutSystems should change this behaviour, but it would be a breaking change, so they probably won't. Apparently on Mobile they made the right decision and always create a copy.

Thanks for responding. I did stumble on this as I did move some logic from server action to client action and it did not work. You can nicely copy paste things like that.

One of the reasons why I'm using the low code is to speed up development and really making it easier, but these kind of design farts are working against that mission, if the "language" definition is not properly understood or it is difficult is not good. So may be there should be improvement request how they should change that. 

Pass by reference would be really good especially on my use case where you fill the list with some sets of actions. 

On my implementation, I will figure out some kind of hack here. 

May be to solution here would be that use still could have input parameter types as pass by reference and pass by value and some of the types would support only some of them.

A similar discussion for pass by reference happened some days back.

It was for web applications however - we have concluded following.

Refer the discussion here: https://www.outsystems.com/forums/discussion/41234/are-list-records-passed-to-child-webbblocks-by-reference-or-by-value/


As conclusion by reference works on these circumstances

1. Works if modification done on child preparation

2. Does not work if modification done on child screen action

----------

3. Works if modification done on server action called from parent's screen action

4. Does not work if modification done on server action called from children's screen action


For mobile, we need to make observations in all such above cases for the pass by reference and pass by value (parameter passing behavior)

Here is my mobile application "PassByReferenceMobile" that I used for testing.

.. and here is the web application "PassByReferenceTest".

Both are for OS 11 and developed at personal cloud.