Use value of input outside block
Application Type
Reactive
Service Studio Version
11.11.14 (Build 48084)

Hello,

I am new to outsystems and can't find the very basics unfortunately.

I structured components into multiple blocks to reuse them in different places within my app that I want to develop.

Lets start with the most simple variant:
A block with an input, connected to an input parameter that is provided by the parent screen.

Value of this input should be saved on the parent screen. But the variable is only transferred into the block but not out of the block where it can be saved. I do not want to save the variable inside the block (because there should be no save button there). 

So how do you use the value/variable of an input outside a block?

Parent screen with inserted block:

Properties of Block with input parameter:

Variable passed to block:


I think this is very basic and i am kind of frustrated that I cannot find the documentation to accomplish such a basic behavior.

Looking forward to you answers. Thank you!

Best regards

Adrian


Hi Adrian,

with that scenario you're sending the value to the parent on every change of the variable in the input, it doesn't include focusOut() actions.

If you're sending immediately the value to the parent using the event on the OnChange you cannot debug it.

If you need some kind of validation before sending to parent, check this oml, it uses a client action on the OnChange that calls the event, allowing some code before the event is triggered.

Regards

TestMasterDetail.oml

Hi Jose,

thank you for your oml file. I think I will implement this also.

Are there any downsides of this additional Client Action within the block? Maybe performance issues?
How would you create the block and Client Actions if the block contains more than one input?

Best regards

Adrian

It's a simple client action without much else, the performance cost is irrelevant.

mvp_badge
MVP
Solution

Hi Adrian,

Based on the shared .oml file below-mentioned are the points which I want to highlight..

  • Your implementation is correct in defining the block event mechanism, i.e. passing the block value to the parent screen.
  • But you have slightly mistaken in using the additional input parameter called ParentVariable defined in the event handler screen action.
  • The defined ParentVariable is a Text data type variable/container which gets newly created (allocated with new space), and its scope is limited to the Handler action flow.
  • When you pass GetQuartettById.List.Current.Quartett.Kat1_Name value as the ParentVariable input parameter value doesn't mean that you are passing the memory reference(address) of the Quartett.Kat1_Name container. Instead, you are passing the attribute's text value residing in the GetQuartettById.List.Current.Quartett.Kat1_Name as the input parameter value. Hence the assignment within the action flow, i.e. ParentVariable = Name assignment, doesn't make any sense, and it is not storing the Name input parameter variable value to GetQuartettById.List.Current.Quartett.Kat1_Name memory space.

                                                 

I do have 2 solution to suggest for this use case..

Solutions:

1) Make an additional parameter to the Handler client action called Index. Within the action flow introduce a switch condition and, based on the index value, assign the Name variable value to the respective record attribute container as I did in SetKategorieHeaderName1 screen action (PFA)

2) Define separate handler action flow for all the block instances within the screen, and in every action flow assign the respective attribute with the Name variable value as I did in SetKategorieHeaderName2 screen action (PFA)

Refer to the attached .oml file


I hope this helps you!


Kind regards,

Benjith Sam

TestMasterDetail.oml

Hi Adrian,

don't get frustrated, it is indeed simple to achieve your intentions but sometimes is not so easy to find in the documentation/courses. That's why it's recommended to follow the courses and learn step by step.

For your problem, you need to create an event in the block that will send back to the parent the value of your input parameter.

Check this page for more details:

https://success.outsystems.com/Documentation/11/Developing_an_Application/Design_UI/Reuse_UI/Use_Events_to_Propagate_Changes_From_a_Block_to_the_Parent

Best regards

Hi Jose, 

thanks for your reply. Unfortunately in the outsystems documentation a predefined value of the block gets passed to the parent to be shown there. There is no saving or assigning to a variable that has been passed to the block. 

But I tried it nevertheless.

1. I created an event within my block:

2. Created a Handler on the parent screen and connected it to the block instance and was hoping to pass the input variable to the "parentvariable" that I want so save.
My goal has not changed, I want to save the variable (kat1_name) that has been changed inside the block (name).

3. Inside the event handler I wanted to assign name to kat1_name:

Still no luck :/

What am I doing wrong?

Best regards

Adrian

You can use a local variable in the block to assign the value you want and pass it in the event as well, in case you don't want to change the input parameter.

In the parent block it looks ok. To have a better understanding of it's being processed you can set some breakpoints in the code to verify the current value of each parameter.

mvp_badge
MVP

Hi there Adrian,

First of all, welcome to OutSystems and to the community!

There is no need to get frustrated, everyone has been in your position. And to be honest, it is normal to struggle a bit with Events at the beginning, but once you understand them, you'll see that they're actually quite simple :)

I was looking into your code and it seems to be correct.

My guess is that you are not triggering Event1 in the KategorieHeader block. You'll need to trigger it so the changes propagate to the parent.

Since you're working with an Input, as a suggestion you could trigger Event1 in the On Change Event of that Input:


This will make that, every time you change that input, Event1 will be triggered and the value will be propagated to the parent.


If this doesn't resolve your issue, please share your OML with us so we can take a look :)


Kind regards,

Rui Barradas

Hi Rui,
hi Jose,

in my previous post I forgot this: 

So therefore I already set the On Change Event on the input in the block.
But I wonder when does the Event get triggered? On every keydown or on focusOut()?

How do I set a breakpoint since I cannot see any code where to put it?

Please find the oml attached.

Best regards

Adrian

TestMasterDetail.oml

mvp_badge
MVP
Solution

Hi Adrian,

Based on the shared .oml file below-mentioned are the points which I want to highlight..

  • Your implementation is correct in defining the block event mechanism, i.e. passing the block value to the parent screen.
  • But you have slightly mistaken in using the additional input parameter called ParentVariable defined in the event handler screen action.
  • The defined ParentVariable is a Text data type variable/container which gets newly created (allocated with new space), and its scope is limited to the Handler action flow.
  • When you pass GetQuartettById.List.Current.Quartett.Kat1_Name value as the ParentVariable input parameter value doesn't mean that you are passing the memory reference(address) of the Quartett.Kat1_Name container. Instead, you are passing the attribute's text value residing in the GetQuartettById.List.Current.Quartett.Kat1_Name as the input parameter value. Hence the assignment within the action flow, i.e. ParentVariable = Name assignment, doesn't make any sense, and it is not storing the Name input parameter variable value to GetQuartettById.List.Current.Quartett.Kat1_Name memory space.

                                                 

I do have 2 solution to suggest for this use case..

Solutions:

1) Make an additional parameter to the Handler client action called Index. Within the action flow introduce a switch condition and, based on the index value, assign the Name variable value to the respective record attribute container as I did in SetKategorieHeaderName1 screen action (PFA)

2) Define separate handler action flow for all the block instances within the screen, and in every action flow assign the respective attribute with the Name variable value as I did in SetKategorieHeaderName2 screen action (PFA)

Refer to the attached .oml file


I hope this helps you!


Kind regards,

Benjith Sam

TestMasterDetail.oml

Hi Benjith, 

this indeed helps me! Thank you very much for your effort marking out two different solutions and providing an example.

As you may have seen, I have a lot of other blocks where I reuse inputs. So therefore I think I go with the switch index inside the handler action.
But for example I have a more complex case where I use up to 32 "card blocks" with multiple inputs each. Should every single input in a "card block" have an On Change event? The respective handler in the parent would get very complex if I use a switch of a index for 32 different "cards".

I assume there is no other solution dealing with that problem from inside of the block instances? Can't I pass the "parent" to the block in some way, so the block can handle the passing of variables to the parent itself?

And I wonder if my use case is so uncommon? Am I thinking too complex or is there really no out of the box solution for this (i.e. implemented directly into the inputs or variable handling of Outsystems)?

Thank you again and

Best regards

Adrian

Hi Adrian,

with that scenario you're sending the value to the parent on every change of the variable in the input, it doesn't include focusOut() actions.

If you're sending immediately the value to the parent using the event on the OnChange you cannot debug it.

If you need some kind of validation before sending to parent, check this oml, it uses a client action on the OnChange that calls the event, allowing some code before the event is triggered.

Regards

TestMasterDetail.oml

Hi Jose,

thank you for your oml file. I think I will implement this also.

Are there any downsides of this additional Client Action within the block? Maybe performance issues?
How would you create the block and Client Actions if the block contains more than one input?

Best regards

Adrian

It's a simple client action without much else, the performance cost is irrelevant.

Hi @Adrian Zuerl , while we deal with blocks , we can send and receive data from/to the blocks in such a way

to send data to the block , we can add input parameters to the block and can send the value accordingly

to send the data out from the block to the parent screen/block we can event out the data

you can refer below links for better understanding

https://success.outsystems.com/Documentation/11/Developing_an_Application/Design_UI/Reuse_UI/Create_and_Reuse_Screen_Blocks 

https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Interfaces/Navigating_in_the_Application/Block


thanks,

Sandeep.

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