Are list records passed to child webbblocks by reference or by value?

Are list records passed to child webbblocks by reference or by value?

  

Hello Everyone,


I am using OutSystems 10.

I have read somewhere on the forum that a record list variable (eg: List of Employee where Employee is a structure) is passed by reference. So - if it  is passed by reference, then if the list record is modified in the child webblock - it should reflect in the parent webblock/webscreen.


Now - I tried to check if this actually happens. So - I created two webblocks, the second being a child of the first webblock. And passed the list record.

So - I tried the debugging, I also tried to display the list record in both the parent and child webblock.

My observation is that:  if the list record gets modified in the child webblock, the modified webblock is not being reflected in parent webbblock.


So - this is in contrast to the behavior expected from variables which are passed by reference.

So want to confirm below:

1. Are variables of list record passed by reference to child webblocks?

2. If this is the case, then please explain my observation.


Regards,

Chetan

Hi Chetan,


Here is an example about Lists. Maybe can help you clarify in a generic way how it works. 

https://www.outsystems.com/forums/discussion/41214/assigning-a-list-a-to-list-b/#Post148177

You can create a similiar example for your specific question and try to check the results.


Kind regards,

Miguel Sousa

Miguel Sousa wrote:

Hi Chetan,


Here is an example about Lists. Maybe can help you clarify in a generic way how it works. 

https://www.outsystems.com/forums/discussion/41214/assigning-a-list-a-to-list-b/#Post148177

You can create a similiar example for your specific question and try to check the results.


Kind regards,

Miguel Sousa

Hi Miguel,


I saw the link you shared.

It is showing the example using a Server action call. I will try that too.

But- the example I tried was using web-blocks and the by reference behavior is not observed for web-blocks.



Regards,

Chetan


https://www.outsystems.com/help/servicestudio/9.1/index.htm#t=Designing_Actions%2FAbout_Input_Parameters.htm

Afaik it only works from screen-to-action not screen-to-screen/block

From my experience, if you input a list to a web block, it is by reference, meaning if the web block changes the list, it's changed in the original screen as well.

Joey Moree wrote:

From my experience, if you input a list to a web block, it is by reference, meaning if the web block changes the list, it's changed in the original screen as well.

But, I just tried it. And it does not behave like a by reference parameter passing for web-blocks.


Eric Halim wrote:

https://www.outsystems.com/help/servicestudio/9.1/index.htm#t=Designing_Actions%2FAbout_Input_Parameters.htm

Afaik it only works from screen-to-action not screen-to-screen/block


I think you are correct..I also observed that the "by reference" characteristic is observed in Action calls. But not in screen-to-screen or block level call.

Solution

Yes probably because block/screen has its own scope... "by reference" only works within same single scope

Solution

Eric Halim wrote:

Yes probably because block/screen has its own scope... "by reference" only works within same single scope


Yes, that makes sense.

I did some testing on this and this is what I found:

  • When you pass the list as an input parameter for a webblock in the same eSpace and manipulate the list in the block's Preparation, the changes are also reflected in the block's parent. So the list is passed by reference.
  • When you pass the list as an input parameter for a webblock in the same eSpace and manipulate the list in a block screen action, the changes are not reflected in the block's parent.
  • When the block is in a different eSpace, the list is always passed by value.

Aurelio Junior wrote:

I did some testing on this and this is what I found:

  • When you pass the list as an input parameter for a webblock in the same eSpace and manipulate the list in the block's Preparation, the changes are also reflected in the block's parent. So the list is passed by reference.
  • When you pass the list as an input parameter for a webblock in the same eSpace and manipulate the list in a block screen action, the changes are not reflected in the block's parent.
  • When the block is in a different eSpace, the list is always passed by value.

Is it possible for you to paste the .oml.

That's because, I tried the same thing. But my results are contrary.

Both the webblocks in my case are in same espace.  In my case, I am manipulating the list in child webblocks screen action.


Sure, here it is.

As you can see, when you manipulate the list in the child block's preparation, those changes are also made to the parent's variable. However, if you manipulate the list in a screen action, the changes are not made to the parent's variable.

Aurelio Junior wrote:

Sure, here it is.

As you can see, when you manipulate the list in the child block's preparation, those changes are also made to the parent's variable. However, if you manipulate the list in a screen action, the changes are not made to the parent's variable.

Haven't got time to test this scenario so in this case block scope will be within the same parent/screen scope yes? This makes sense too because on Preparation like more on parent/global as compared to screen action as sub action within the same screen class.


Eric Halim wrote:

Aurelio Junior wrote:

Sure, here it is.

As you can see, when you manipulate the list in the child block's preparation, those changes are also made to the parent's variable. However, if you manipulate the list in a screen action, the changes are not made to the parent's variable.

Haven't got time to test this scenario so in this case block scope will be within the same parent/screen scope yes? This makes sense too because on Preparation like more on parent/global as compared to screen action as sub action within the same screen class.


Yes, so we can conclude that: since screen actions are a separate scope they cannot preserve the by reference behavior.


Aurelio Junior wrote:

Sure, here it is.

As you can see, when you manipulate the list in the child block's preparation, those changes are also made to the parent's variable. However, if you manipulate the list in a screen action, the changes are not made to the parent's variable.

Hi Aurelio,

 

I have try as you said, and its works.

My question is why it is different when you manipulate the ListParam from inside child block preparation vs child block button action, I think the ListParam is global in child block.

Does anyone can explain this?


Regards,

Eddy


Eddy Krismanto wrote:

Aurelio Junior wrote:

Sure, here it is.

As you can see, when you manipulate the list in the child block's preparation, those changes are also made to the parent's variable. However, if you manipulate the list in a screen action, the changes are not made to the parent's variable.

Hi Aurelio,

 

I have try as you said, and its works.

My question is why it is different when you manipulate the ListParam from inside child block preparation vs child block button action, I think the ListParam is global in child block.

Does anyone can explain this?


Regards,

Eddy


Hello Eddy,


Even I would like a definitive answer on this. Someone also mentioned the "scope" as the reason behind this which makes sense.

I can make a reasonable guess based on how programming languages work.

OutSystems is at the end going to generate code in C# or Java.

The button action is a screen action - it is basically a callback or event handler for the button click event. In a event handler, not all the parameters of the calling method are available. Only event information and any parameters you pass are available. This somehow is excluding the global variables to be able to be changed in the screen actions (by reference).

Maybe someone from OutSystems can define this better.



Chetan Yewale wrote:

Hello Eddy,


Even I would like a definitive answer on this. Someone also mentioned the "scope" as the reason behind this which makes sense.

I can make a reasonable guess based on how programming languages work.

OutSystems is at the end going to generate code in C# or Java.

The button action is a screen action - it is basically a callback or event handler for the button click event. In a event handler, not all the parameters of the calling method are available. Only event information and any parameters you pass are available. This somehow is excluding the global variables to be able to be changed in the screen actions (by reference).

Maybe someone from OutSystems can define this better.

And somehow by doing "screen action" you created another variable locally which is not referenced to parents while on preparation it is the same variable thus "referenced".

Yes I hope someone could elaborate more on this why technically the reasoning behind it differs on preparation and screen action.


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

Eric Halim wrote:

Chetan Yewale wrote:

Hello Eddy,


Even I would like a definitive answer on this. Someone also mentioned the "scope" as the reason behind this which makes sense.

I can make a reasonable guess based on how programming languages work.

OutSystems is at the end going to generate code in C# or Java.

The button action is a screen action - it is basically a callback or event handler for the button click event. In a event handler, not all the parameters of the calling method are available. Only event information and any parameters you pass are available. This somehow is excluding the global variables to be able to be changed in the screen actions (by reference).

Maybe someone from OutSystems can define this better.

And somehow by doing "screen action" you created another variable locally which is not referenced to parents while on preparation it is the same variable thus "referenced".

Yes I hope someone could elaborate more on this why technically the reasoning behind it differs on preparation and screen action.


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

Good summary!