319
Views
4
Comments
Solved
Refresh a web block within multiple web blocks.
Question
Application Type
Reactive

I have a web block that takes a parameter as the product Id to render the information in that web block, so now it will render multiple web blocks according to the id. And I have a function to add information and have to reload the web block containing the changed id. Can it be done?

2022-01-13 11-06-04
Neha Sheikh
Champion
Solution

Hello Vo,

Yes, this is possible. Since you have an input parameter passed to the block and you are showing data based on that input parameter you need to use OnParameterChanged Event and handler to show data related to the new ID always.

You can see that in the attached OML. I am saving information also in this OML but in my case, the data is passed to the screen and then it Is saved.

Let me know if this helps and also if you have any further questions.

Regards,

Neha

BlockDemo.oml
UserImage.jpg
Vo Ngoc Truong

Thank you, I did it, and I have another related thing which is I have a list of tasks, for example task 1, when clicking on task 1, it will show task 1.1 task 1.2, task 2 will have task 2.1 2.2, I use web block to render the interface of list task 1.1 task 1.2 (it's like a submenu). Next, I have an add button next to it to add for example add task 1.3 to task 1. so when clicking that add button, it will only refresh the data of the task id that I added to. Can you help me thank you.

2023-04-16 15-25-31
Krishnanand Pathak

Hi @Vo Ngoc Truong,

Web blocks auto re-renders whenever an input parameter changes.

You can also check the below thread for details
https://www.outsystems.com/forums/discussion/82859/webblock/#

Regards
Krishnanand Pathak

2022-01-13 11-06-04
Neha Sheikh
Champion
Solution

Hello Vo,

Yes, this is possible. Since you have an input parameter passed to the block and you are showing data based on that input parameter you need to use OnParameterChanged Event and handler to show data related to the new ID always.

You can see that in the attached OML. I am saving information also in this OML but in my case, the data is passed to the screen and then it Is saved.

Let me know if this helps and also if you have any further questions.

Regards,

Neha

BlockDemo.oml
UserImage.jpg
Vo Ngoc Truong

Thank you, I did it, and I have another related thing which is I have a list of tasks, for example task 1, when clicking on task 1, it will show task 1.1 task 1.2, task 2 will have task 2.1 2.2, I use web block to render the interface of list task 1.1 task 1.2 (it's like a submenu). Next, I have an add button next to it to add for example add task 1.3 to task 1. so when clicking that add button, it will only refresh the data of the task id that I added to. Can you help me thank you.

2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi @Vo Ngoc Truong ,

I'm not following exactly what you are doing, but if I'm reading you correctly, the generic problem you are trying to solve is : 

When I have a list of webblocks, and I know that only the data of one of them needs to be refreshed, how do I do that ?

Is that the question ?

So there is 2 questions here :

  • how do you tell a webblock to refresh itself ?
  • how do you only target the one webblock that needs refreshing, and not all the others ?

part one

The only low code way to tell a webblock to do something from the outside, is through it's OnParametersChanged.  So let's say you only pass in the id of a task, and that id is not changing, (only the record data identified by that id) you will have to add an extra artificial input parameter on the webblock to force an OnParametersChanged.  I see often that a boolean is used for this called "NeedsRefresh" or something like that, I personally prefer to use a counter.

So 

  • on your BlockX, add an extra input parameter called "RefreshCounter", type integer
  • in the OnParametersChanged, you can refresh the data of the block
  • in the parent screen, add a local variable called "BlockXRefreshCounter"
  • whenever the parent wants to tell the block to refresh, just add 1 to the local variable

part two

Now you have a list of blocks in the parent, and you only want to refresh the single block that needs it.  So you can't get away with a single local variable anymore, you'll need a list of counters.

  • make sure your aggregate has an extra calculated Attribute called RefreshCounter.  It can just be 0 or -1 or anything you like to start with
  • you have probably put blockX in a list element on your canvas that has GetTasks.List as source, so map the GetTasks.List.Current.RefreshCounter to the input of BlockX
  • now, in your screen logic, if you think that the task with id 547 needs refreshing, do a ListIndexOf(Id = desired Id), and then, if position not -1, add 1 to GetTasks.List[ListIndexOf.position].RefreshCounter

Dorine

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