36
Views
4
Comments
Solved
Triggering Save Action from Block using a Button on Screen in Outsystems
Question

Hi Everyone,

I need some help with a scenario in Outsystems.

Here’s the setup I have:

  • I’ve created a Block, and inside this Block, I’ve created a form with fields like Att1, Att2, etc.

  • Inside the Block, I’ve also created a Save action that saves the form data into the database.

  • On a screen, I’ve called the Block, and within that screen, I’ve created a button that I want to use to trigger the Save action inside the Block.

Now, my question is: How can I trigger the Save action inside the Block from the Save button on the screen?

Note: I want the SaveAction written into Block only not on Screen

Thanks in advance for your help! Looking forward to your suggestions.

2025-01-23 09-22-22
ABHIJITH G
Champion
Solution

Hi @Neha Singh,
If you have to do the save action inside the block but need to trigger the action from the parent screen or block, you can follow the points below.

  1. Add an Input Parameter to the Block:

    • Create a Boolean input parameter (e.g., IsSubmit) in the block.

    • Set its default value to False.

  2. Use OnParameterChange to Handle the Save Action:

    • Inside the block, implement the OnParameterChange event.

    • Check if IsSubmit is True, then trigger the save action.

  3. Create a Local Variable in the Parent Screen:

    • Define a local variable in the parent screen with the same data type as the block’s input parameter (IsSubmit).

  4. Modify the Local Variable on Button Click:

    • When the button is clicked, change the local variable’s value.

    • Example: If IsSubmit is False, set it to True on button click.

  5. Trigger the OnParameterChange Event in the Block:

    • Since the block’s input parameter is bound to the local variable, changing it triggers OnParameterChange.

    • In OnParameterChange, check if IsSubmit is True, then execute the save action.

  6. Ensure the Condition Before Proceeding:

    • In OnParameterChange, add a condition to verify IsSubmit = True before proceeding with the save action.

  7. Trigger event

    • After the execution of the save action triggers an event to handle at the screen for changing the IsSubmit to false

Use the below link to understand more about screen and block life cycle events.

https://success.outsystems.com/documentation/11/building_apps/application_logic/screen_and_block_lifecycle_events/


Thanks


2025-01-14 07-39-38
Neha Singh

Hi @ABHIJITH G,

Thanks for your suggestion! I have implemented it the way you described, and it’s working. However, I’ve encountered an issue:

  • When I click the Save button for the first time, the action triggers and works fine.

  • But when I click the Save button again, the Save Action does not trigger.

  • Then, when I click it a third time, it triggers again.

It seems like the action is only triggering on alternate clicks. Do you have any idea why this might be happening? Any suggestions on how to ensure the action triggers consistently on every click?

Thanks again for your help!

Demo_Block.oml
2025-01-14 07-39-38
Neha Singh

Thank You @ABHIJITH G , Now its working fine

2025-01-23 09-22-22
ABHIJITH G
Champion

Hi @Neha Singh ,
After saving, you have to change the screen local variable IsSave to false. 
So, you can create an event in the block and trigger it after the save action. Then, while handling the event in the parent screen, you have to change the IsSave = false


Hope this helps.
Thanks

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