Events vs screen actions

I'm having touble to understand what events really are. So far form what I've read, they are a way of passing info from the "block" to the "parent" and trigger some action on the parent, forcing the parent to deal with the triggerd action using the "Handlers".

This make me confused because it seems that you can archieve the same thing whith a screen action? correct?

Or does a screen action only have scope inside its own block/screen? 

To me events and screen actions seem to be very simillar and I'm having a hard time to understand when you use one over the other. Not to mention the confusion with the event handlers from the parent. 

Can someone clarify these doubts? 

Thank you

Hi Tiago,

Since the scope of a block is self-contained, the block and its logic do not have access to the parent scope directly and vice-versa.

Since Blocks allow input parameters, they can be used to pass information from the parent(Screen) to the Block.

We can use events to create a communication channel between the block and the parent. If we need to pass some data from block to parent screen for that we need to create event in block and handler in parent.


Thanks


mvp_badge
MVP
Solution

Hi Tiago,

Like Vinod already wrote, Screen Actions have scope over the Screen or Block they are part of. That means that a Screen Action of a Screen can access all Local Variables etc. of that Screen, but not of any Block that's part of that Screen. Similarly, a Block's Screen Actions (that should rather be called "Block Actions") can only access Local Variables etc. that are part of the Block, but nothing outside the Block.

Since the Block has (optionally) Input Parameters, a Screen can pass information to the Block by changing the Input Parameters. You do need to add an OnParametersChanged event to handle the change in Input Parameters in that case. Without an OnParametersChanged, the Block will not get notified of a parameter change (note that for Traditional Web, you need to refresh the Block instead).

Conversely, when a Block wants to notify something to the Screen it is contained in, e.g. when a user presses a button that needs to be handled by the Screen logic, you need to define an Event. The Event can define Input Parameters, which is a bit of a tricky name here, as they're input to the screen, but output to the Block (as in: the Block outputs the data, as input for the Screen). If the Event is mandatory, the Screen must define a handler (which is a Screen Action), otherwise it's optional.

So to address your confusion: an Event is just like any other event that can be handled in a Screen (or other Block), e.g. the On Ready or On Destroy, or an On After Fetch, only it's sent by your code, as opposed to the OutSystems framework.

Hi Tiago,

Since the scope of a block is self-contained, the block and its logic do not have access to the parent scope directly and vice-versa.

Since Blocks allow input parameters, they can be used to pass information from the parent(Screen) to the Block.

We can use events to create a communication channel between the block and the parent. If we need to pass some data from block to parent screen for that we need to create event in block and handler in parent.


Thanks


mvp_badge
MVP
Solution

Hi Tiago,

Like Vinod already wrote, Screen Actions have scope over the Screen or Block they are part of. That means that a Screen Action of a Screen can access all Local Variables etc. of that Screen, but not of any Block that's part of that Screen. Similarly, a Block's Screen Actions (that should rather be called "Block Actions") can only access Local Variables etc. that are part of the Block, but nothing outside the Block.

Since the Block has (optionally) Input Parameters, a Screen can pass information to the Block by changing the Input Parameters. You do need to add an OnParametersChanged event to handle the change in Input Parameters in that case. Without an OnParametersChanged, the Block will not get notified of a parameter change (note that for Traditional Web, you need to refresh the Block instead).

Conversely, when a Block wants to notify something to the Screen it is contained in, e.g. when a user presses a button that needs to be handled by the Screen logic, you need to define an Event. The Event can define Input Parameters, which is a bit of a tricky name here, as they're input to the screen, but output to the Block (as in: the Block outputs the data, as input for the Screen). If the Event is mandatory, the Screen must define a handler (which is a Screen Action), otherwise it's optional.

So to address your confusion: an Event is just like any other event that can be handled in a Screen (or other Block), e.g. the On Ready or On Destroy, or an On After Fetch, only it's sent by your code, as opposed to the OutSystems framework.

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