Hi everyone!
I need to trigger a child block action from a parent block. Is it possible to implement this?
@Łukasz Kaproń : What you are asking is possible but using JavaScript. Documentation of the same is available at https://success.outsystems.com/documentation/how_to_guides/front_end/how_to_call_a_block_action_in_a_mobile_screen/ . Even though it says its for mobile it works on Web App too.
Basically you create a top level container in the block and on Onready you register your methods to be exposed. Then in the consumer you get the blockId and call the method you registered earlier. Please try it out.
I'm using this in a scenario where I need to handle multiple types of changes from the parent block and want to trigger them in the child block.Create a structured input parameter for the child block.
InputContract
└── ActionFlags (structure)
├── IsAChanged (Boolean)
└── IsBChanged (Boolean)
LocalParam (to save the change at the end of process OnParametersChanged )
OnParametersChanged:
If ActionFlags.IsAChanged <> LocalParam.IsAChanged
Then
Run ActionA()
If ActionFlags.IsBChanged <> LocalParam.IsBChanged
Run ActionB()
LocalParam = ActionFlags => On Parent Block=> when need to trigger action to child block=> just change value = not current valueset value => ActionFlags.IsAChanged = not ActionFlags.IsAChanged
You can do the following:
1- add a local variable in the parent screen call it ChildGUID .
2- Add an input parameter in the block contain GUID.
3- Add an OnParametersChanged action on the block and assign it to the block events.
4- On the parent action, change the ChildGUID to trigger the OnParametersChanged action.
When you click the action on the parent screen the GUID will change and this will trigger the action on the block
It almost meets my expectations, but I have more than one Input Parameters and I would like to trigger a different actiona depending on which one was changed.
Hi Lukasz,
Please check this article, it should asnwer your question: Pass Data Between Blocks - OutSystems 11 Documentation
Way 1:
In Child block:
In_Flag: False
Local_Flag: False
u use OnParametersChanged if In_Flag <> Local_Flag then call your action() and Local_Flag = In_Flag
In Parent block:
In_Flag of child block use Local_Flag in Parent
when u want trigger child action u can set Local_Flag = ! Local_Flag in parent blog
Way 2:
use ParametersChanged in DevPatterns_Lib to trigger your action
In Parent block: implement same way 1
Hope this helps!
Hello,
It is the same as the relationship between a parent screen and a child block. For example, you add an input parameter to the block and place the block in the screen, then assign the input parameter with a value in the screen (the parent), keeping in mind to refresh the block in OnParametersChanged.
The exact same concept applies to a parent block and a child block. In this case, the parent block takes the role of the screen from the previous example.
You can create an input parameter in the child block, and I suggest making it a DateTime type. In the OnParametersChanged event, check whether this value is null or not. If it’s null, nothing happens. If it’s not null, you call the action you need.
In the parent block/screen, create a local variable that always starts with NullDate(). Whenever you need to trigger the child block’s action, simply change this variable from NullDate() to CurrDateTime(). After executing the operation, the child block should trigger an event back to the parent so you can reset the local variable again to NullDate().
Check the OML in the attachment, I created an example where the parent screen triggers an action that performs form validation in a child block.
1. Introduce a new Boolean variable in Parent Block. eg: Flag
2. In Parent block assign flag = If(Flag,False,True) (whenever you want to trigger child block action)
3. Add mandatory boolean input parameter in child block
4. pass Flag from parent block to child block input parameter
5. use OnParameterChange to trigger a child block action
I usually use this approach, too
On step 2, my assignment is flag = not flag, the binary function makes more sense than the if statement
On step 5, if there are more inputs that will cause some data to be refreshed, we need to declare a local flag (to be set in OnInitialize and OnParameterChanged) to compare with the input flag then decide to refresh data or not
The simplest way to trigger a child block action from a parent block using OnParameterChanged is this:
Expose an input parameter in the child block This parameter will control when to run the child’s action. Example: Input Parameter: TriggerAction (Boolean)
Inside the child block, use OnParameterChanged for this parameter When TriggerAction changes, the child block automatically detects the change.
In OnParameterChanged, write a condition If the parameter value meets your condition, call the child block action. Example: If TriggerAction = True → Run the internal logic
From the parent block/screen, update the TriggerAction parameter Whenever the parent updates the parameter value, the child block action will run.
Here is the clean logic flow:
Parent block• Has an event or condition• Sets ChildBlock.TriggerAction = True (or any value you want to check)• This automatically fires OnParameterChanged in the child
Child block• OnParameterChanged runs• Inside it, check: If TriggerAction = True• Call the child’s action• Optionally reset TriggerAction back to False to avoid looping
This method works universally in OutSystems because:
• OnParameterChanged is invoked automatically each time the parent updates a value
• No manual event wiring is needed
• No dependencies or refresh issues
• Cleanest and fastest way to control child logic from the parent