Ajax Refresh does not clear local variables

Hi,

In our web app we have a screen and a web block that is refreshed using Ajax Refresh with updated input parameter. Inside web block we have a list that is populated by using AppendAll from one of the aggregate on preparation action. 

We now noticed that whenever web block is refreshed and preparation is started local variable that holds the List is not empty so with each refresh we have more items in the list... That is not a big problem to solve as using ListClear or Assignment instead of appending solves the issue. However the whole idea seems to be not correct - if block is refreshed and preparation is triggered all local variables should have default values and list should be clear. 

Is it a bug or I missed something in documentation updates?


Solution

Hi Mykola,

The documentation states that Submit and Ajax Submit does not reset variables (Input Parameters and Local Variables). Usually, we think of this only when we are calling a Screen Action. But when we "Ajax Refresh" a Web Block, and this happens from inside a Screen Action called with Ajax Submit, it is valid for the web block as well.

So, by default, when you "Ajax Refresh" a web block, while its preparation will run again and the input parameters will be reinitialized with values passed from the parent, the local variables will not change automatically.

At the beginning this also seemed weird and not natural, but the truth is that this behaviour helped me a lot in many situations.

Cheers.

Solution

When I started with OutSystems I also stumbled on this, found it weird but now appreciate.

But I think OutSystems could do a better job in explaining this in master classes, likewise stuff like how to keep your viewstate small.

Typical problems starters do not easily understand, as this is not really associate level topics and not good documented.