38
Views
2
Comments
blocks lifecycles with server actions

i read how OS manage lifecycle and i tried some test and i found a behavior that can't undestand.

i have a screen, with a block.

each have event on Init and the screen have a container with the visibile binded to a function.

with js i create elements to undestand what's happened.

so, screen init call a client action, the same thing in block.

this is the result. as shoud be.

but the lifecycle change if in the client action there is a server action.

now, block action finish after container function.

why?!

in my oml you can check running screen1 and screen2

BlocksLyfeCycle.oml
2025-12-09 14-11-18
Janakiraman JR

Hi Emanuele,

It sounds like you're observing a change in execution order depending on whether a server call is present inside a client action. Let me break this down and explain why that behavior happens. 

In Screen1, when there's no server-side action inside the OnInitialize:

  1. Screen.OnInitialize runs.

  2. Block.OnInitialize runs.

  3. Then expression evaluation like your Visible function on the container happens.

All client-side actions are executed synchronously, so execution order is preserved and predictable.

In Screen2, you added a server action call inside a client action. This introduces asynchronous behavior. What happens now is:

  1. Screen.OnInitialize starts.

  2. Block.OnInitialize starts.

    • It encounters a server call, which is asynchronous under the hood.

  3. While waiting for the server response, OutSystems does not block the rest of the JavaScript engine.

  4. So, the container’s visibility function is executed before the server call in the block finishes.

This is similar to how Promises or async/await work in JavaScript, when the code awaits a network response, the JS engine keeps going.

This happens due to OutSystems compiles client-side logic into JavaScript. When you call a server action:

  • It gets translated into an AJAX call, which is asynchronous.

  • As a result, anything that doesn’t depend on the server result will keep executing.

  • The visibility function on the container is one of those things it doesn't "wait" for the block’s OnInitialize to finish.

UserImage.jpg
emanuele mantovanelli

hi,

thank you for answer. it's very clear and make sense :_)

but, if i run the same client action with inner server action from screen init (the same of block's action), will run sync and not async as from block.

try to check screen2 in my oml.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.