18
Views
7
Comments
Solved
Update entity in screen and in web block in the same screen

Hi!


I have a context where there is a template and a Template can have many sections. In the TestScreen I have is possible to edit the template information. But I also want to allow to edit the section information in this screen. The sections are already being displayed in this screen and the user can navigate between the sections. The section info is inside a web block. My doubt is how to pass the section information to a screen action to allow for the update of the section? 


I have a OML with the example. The screen action "Save" is to save the section but Im not understanding how to achieve that.


Thanks!

test.oml

Rank: #93
Solution

Hello again Jake,

Thank you for sharing the latest version.

Responding to your questions: to pass data from a block to its parent with an event, you'll need to trigger that event. Usually it is done using a button or a link.

It seems that your use case is a bit different, since you have your button outside the block. In this scenario, you won't have access to the variables inside the block, because they are not accessible in the parent scope. That's why it is better to have the button inside the block, it just facilitates your code.


However, if you really want to have it that way, it is possible to have that button in the parent screen and still accomplish what you pretend. It's a bit more complex, still doable :)


Let me give you an example:

What you can do is to have a hidden button inside the block SectionDetailWB (this button won't be visible for the user) and this button calls a screen action (in the block) to save your section details (SaveSection).


After this, back to your parent screen (TestScreen), when you press in the Save Section button, you will need to trigger that hidden button.

For example, you can do this using JavaScript (RunJavaScript action from HTTPRequestHandler extension) in order to force this click in this hidden button. Basically the JavaScript will search for this hidden button in the entire page and trigger it.


Please refer to attached OML file.


Hope that this helps you!


Kind regards,

Rui Barradas

testscreen.oml

Rank: #13701

Thanks! Do you know if is possible to use ID instead of class and if there is a better use id or class or of its the same?   

Rank: #93

Hello again Jake,

It should be possible to use Id instead of Class :)

In this scenario, you control both of them, so it is practically the same.


Kind regards,

Rui Barradas

Rank: #93

Hello Jake,

Hope you're doing well.

I was looking to your file and I couldn't find your TestScreen neither the Section info is inside a Block.

Are you sure that this OML is the last version? :)


Nevertheless, if you want to pass data from a Block to its parent (screen or other Block), you can do it using Events and Handlers.

Please take a look into this documentation, it may help you:

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

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


Let us know what you want to accomplish and if you have any doubts about this topic :)

Hope that this helps you!


Kind regards,

Rui Barradas

Rank: #13701

But is possible to pass data with events without buttons in the web block? But it's not possible to have the button in the parent screen or is really better to have inside the web block? To test the OML probably you need to create first a new Template. And then, in the Templates page is only necessary to click in that created template to go to the TestScrenn where it should be possible to edit the section but also the template.  

Thanks!

testscreen.oml

Rank: #171

Hi Jake,

I did not locate the TestScreen on your sample.

However with your explanation I think I had an idea of what you are trying to do.

When you have a web block and some input fields inside it, you will not be able to access this info in the parent scope, being it a screen or another web block.

If you want to save some data in both the parent and the child, supposing they are nested (One inside the other) you can try to place your save button inside the children block, where you have access to the data and can save the info using an update action and then trigger an event inside the child to warn its parent that the save button was clicked.

This way you can also call an update action on your parent scope in the event handler to save the changes.


Let me know if this helped or if it is too much complex, so I can try to make a sample for you.

Cheers and Regards,

RR  :)

Rank: #13701

Hi!

Sorry, this is the correct OML. 

To test probably you need to create first a new Template. And then, in the Templates page is only necessary to click in that created template to go to the TestScrenn where it should be possible to edit the section but also the template.  





Thanks!

testscreen.oml

Rank: #93
Solution

Hello again Jake,

Thank you for sharing the latest version.

Responding to your questions: to pass data from a block to its parent with an event, you'll need to trigger that event. Usually it is done using a button or a link.

It seems that your use case is a bit different, since you have your button outside the block. In this scenario, you won't have access to the variables inside the block, because they are not accessible in the parent scope. That's why it is better to have the button inside the block, it just facilitates your code.


However, if you really want to have it that way, it is possible to have that button in the parent screen and still accomplish what you pretend. It's a bit more complex, still doable :)


Let me give you an example:

What you can do is to have a hidden button inside the block SectionDetailWB (this button won't be visible for the user) and this button calls a screen action (in the block) to save your section details (SaveSection).


After this, back to your parent screen (TestScreen), when you press in the Save Section button, you will need to trigger that hidden button.

For example, you can do this using JavaScript (RunJavaScript action from HTTPRequestHandler extension) in order to force this click in this hidden button. Basically the JavaScript will search for this hidden button in the entire page and trigger it.


Please refer to attached OML file.


Hope that this helps you!


Kind regards,

Rui Barradas

testscreen.oml

Rank: #13701

Thanks! Do you know if is possible to use ID instead of class and if there is a better use id or class or of its the same?   

Rank: #93

Hello again Jake,

It should be possible to use Id instead of Class :)

In this scenario, you control both of them, so it is practically the same.


Kind regards,

Rui Barradas