Is preparation called once? [Possible bug?]

Is preparation called once? [Possible bug?]

  

Good Day,

I do not know if this is a known issue as I cannot find a related post. I realise that when I use listappend in preperation, it is called again if use listappend in another screen action. Is preparation only called once or is it called multiple times? 

I can't tell if this is a bug or not as the documentation does not state specifically if it is suppose to be called only once. However it seems to be only called whenever I use listappend, and it does not trigger if I use a server action. If it is expected to be called multiple times, it should be written somewhere as this may cause developers to think that they are facing another issue.

A quick fix is to have an if statement with a boolean condition in start of the preparation. Once the preparation is run once, the boolean value toggles and whenever it enters the preparation action again, it will simply skip the rest of the code due to the if statement and head straight to end. 

https://www.outsystems.com/help/SErviceStudio/9.0/Designing_Actions/Create_the_Screen_Preparation.htm

Regards,
Jerome Lieow


Solution

Hi Jerome,

I believe the behaviour you are observing has nothing to do with calling ListAppend in a Screen Action.

I suggest you go through training videos again, namely the Screen Lifecycle: Interaction (the explanation around the 3:47 mark is particularly relevant for your question, I think): If a Screen Action is called with Submit method and finishes with an End node, the server will re-execute the Preparation and rebuild the screen before sending the response back to the browser. 

Solution

Also, you can find the behaviour explained in the documentation here.

Hi Lieow,

From this article:

- the screen preparation is automatically executed.

- if you use Ajax refresh then only part of the screen is refreshed (i think it does not call preparation again)

- You can call the preparation again by replacing the End widget with the Screen where you want its preparation is executed again.

- For blocks, it will be executed again.

The best to try it is use a feedback message on the preparation to see whether it is executed or not.

regards,

indra


Indra Budiantho wrote:

Hi Lieow,

From this article:

- the screen preparation is automatically executed.

- if you use Ajax refresh then only part of the screen is refreshed (i think it does not call preparation again)

- You can call the preparation again by replacing the End widget with the Screen where you want its preparation is executed again.

- For blocks, it will be executed again.

The best to try it is use a feedback message on the preparation to see whether it is executed or not.

regards,

indra


Hi Indra, 

Preparation is called even with Ajax Refresh. I guess it is part of how outsystems work and I won't be able to change it.

Regards,

Jerome Lieow


Jorge Martins wrote:

Hi Jerome,

I believe the behaviour you are observing has nothing to do with calling ListAppend in a Screen Action.

I suggest you go through training videos again, namely the Screen Lifecycle: Interaction (the explanation around the 3:47 mark is particularly relevant for your question, I think): If a Screen Action is called with Submit method and finishes with an End node, the server will re-execute the Preparation and rebuild the screen before sending the response back to the browser. 

Hi Jorge,

Thank you for pointing me to that video. I guess it is part of outsystem's logic so I will have to learn to live with it.

Regards,

Jerome Lieow.


Hey Indra and Jerome. You had a few misunderstandings in your posts, so let me clarify this topic.

But first, please stick with Jorge Martins' excellent answer. There's no need to continue the discussion and cause confusion to yourselves and other readers.


The preparations is used to prepare data before being displayed. It runs before the screen is rendered for the first time (what in .NET is called Page_Load). It is executed again when the page needs to be completely re-rendered, on a Submit action (this is called Postback in .NET). In no other occasion a screen preparation will execute.

When doing an ajax refresh, you are refreshing just a small part of the screen. There's no point in running the preparation again, because it may contain queries and logic that won't be needed for the small part being refreshed. On the web platform, the burden is on the developer to refresh the queries and perform any logic before refreshing the part of the screen. Note that, in the mobile platform, these concepts no longer exist, because the burden is no longer on the developer to prepare data before being displayed, or to explicitly refresh a part of the screen.


Now for web blocks. The preparation of web blocks, again, is to prepare data before being displayed. Just like web screens, the preparation runs before the web block is rendered for the first time, and when it needs to be completely re-rendered. Submit actions re-renders the whole page, so web block preparations are also executed as a consequence. For ajax refreshes it really depends on whether the whole block is refreshed or not. If the whole block is refreshed, then the preparation is executed (it will be re-rendered, after all); otherwise, it isn't executed.


Lastly, if you replace the End node with another one (a screen or a download), the preparation won't be executed, even on Submit requests. Why? Because the screen won't be re-rendered, if you're redirecting to a new screen or downloading a file.