Determining which web block was edited in a list of web blocks

Determining which web block was edited in a list of web blocks

  

Hello,

I'm wondering how I can get data back from a web block when it has changed. The problem is that I have a list of web blocks on my page. Every web block has an editable table widget. So on the page it looks like a list of tables under each other. When I make changes in one table, I call the OnRowSave action, and there I notify the parent (the screen) with a JSON message (because I can't return a structure). But how does the parent know in which web block the notify was called? Because I have to edit my structure but I don't know which table has been edited.

Ps. I'm not using the database since I get and post my data from a REST service. 

Hi Joeri,

The only way to the parent to know in which web block the data was edit, is to explicitly tell him.

You can do it in the notify message itself, or you can use a session variable, for example.
I prefer the notify itself.

In this case, you can include the information in the JSON itself (another field), or separate, in the message, like this:

"webblock1|{your jason}"

When you get the notify message, you split the message through the | (pipe) separator using the split text function (Text extension), that will give you a LIST of strings, where the first will be "webblock1" and the second will be your json.

Now you only need to give names to your webbloks that you send back in the message and act accordingly :)

Cheers,
Eduardo Jauch

P.S.

There are other ways, but I think this is the easiest one.

Hi Joeri,

Adding to what Eduardo has said...

From what I understand of your issue you can:

  • Have different OnNotify Actions for each Web Block (that's a property of the instance of the Web Block)
  • Or, add an input parameter in the Web Block and pass them some identifier. Then, return that identifier in the JSON. That way you can identify which block sent the notify.

Cheers,

José

José Costa wrote:

Hi Joeri,

Adding to what Eduardo has said...

From what I understand of your issue you can:

  • Have different OnNotify Actions for each Web Block (that's a property of the instance of the Web Block)
  • Or, add an input parameter in the Web Block and pass them some identifier. Then, return that identifier in the JSON. That way you can identify which block sent the notify.

Cheers,

José

That's a nice solution if the number of webblocks is small and fixed. :)


Thanks for your quick replies guys. I thought of giving an identifier to a web block as well, but then I had the problem that inside the list of web blocks, I can't actually "search" for the webblock identifier that is returned since I don't have access to those properties there.

Hi Joeri,

You could use the CurrentRowNumber as identifier. Pass that value as input parameter of the web block and get it back in the json. And you can access an element of the list using:

WebBlockListTable.List[<IndexReturned>].<something>

Cheers,

José

José Costa wrote:

Hi Joeri,

You could use the CurrentRowNumber as identifier. Pass that value as input parameter of the web block and get it back in the json. And you can access an element of the list using:

WebBlockListTable.List[<IndexReturned>].<something>

Cheers,

José

Tried that as well, but unfortunately in my case items can get deleted and then the CurrentRowNumber doesn't match the identifier anymore. So for example if i have the following list (simplified):

List[0] = 0

List[1] = 1

List[2] = 2

And the List[1] item gets deleted, then the numbering doesn't match anymore:

List[0] = 0

List[1] = 2 

Hi Joeri,

If the source of the list records is a list from an aggregate/sql, you can use the record ID as identifier to the webblock.

Another possibility is to add a new attribute to the source list and iterate the list setting ids (through a counter), giving each item its own id. This way, if one item is removed, the others still have the identifier.

Cheers,
Eduardo Jauch

EDIT.

You can aways itereate the ListRecord list to find the correct item, if you need.

I don't use an aggregate since all of my data is coming from a REST API service. Basically I'm using a relatively complex structure for storing my data, then a home made form shows all this data and the user can edit that. When the user presses "save", all the data is posted back to the API. But one of this structure's attribute is a list of lists element and that is where the list of web blocks (in fact list of tables) comes in. One variable holds all this data and when a user changes the data, it is updated in this structure. But when a user clicks "save", all of the data which is edited in the webblock-lists is gone since the screen cannot access this data.

I think if I add another property to this structure I'm afraid it doesn't parse correctly anymore and I don't quite understand what you want to do with this since I still can't access the variables of web blocks (where the identifier is stored).

Also, how can I iterate through a list of web blocks? I can't do something like "for each web block, check if the identifier matches the identifier I got from the web block message"

EDIT: maybe I can fix a .oml file so I can show you what I want but that will have to wait till next week unfortunately.

Okay I fixed an .oml file so that you can see what I want to do.

You can find comments in the "OnNotify" action and in the "OnTestItemTableRowSave" action.

Hence that this is a simplified version, so it isn't possible to add or delete tables in this version.



Anyone?

Hi Joeri,

From what I saw, you have to add more data to your structure. To identify the blocks.

Thus, create a new structure, that has the ConditionItem and also an identifier. From the Conditions create a new list where you populate the new list with the values from the ConditionItems.

Having the identifier allows you to know which item in the new list that has to be updated.

When you click the SaveAll just recreate the old list with the values from the new list.

Does this make sense? :)

Cheers,

José

Hello Joeri,

Please, see attached OML.
Note that I did a few changes to your initial file, like I changed the "Save All" button to show the info (and to use Ajax Submit).

I don't think this is very "performant"...
But using directly the result of the web service, I don't see many other options.

I also add a delete button to the lines, to you to see that the "CurrentRowNumber" still works even in this scenario.

Hope it helps.
If you have any question regarding thhe solution, feel free to ask :)

The online example is here: https://eduardojauch.outsystemscloud.com/API_test/Home.aspx?_ts=636479908155447379

There is a quirk. the Editable Table, when you "remove" one element, disappears with the last line. The line IS there, but it wont show. I already saw this before, but didn't had time to deal with it. As son as I have time, I'll try to address the issue.

In any case, if you opt to use other thing than the Editable Table, the logic itself should work without problems.

Cheers,
Eduardo Jauch

Solution

Ok, here is how I fixed it: I used the HashTable plugin from the forge. I create a mapping in which I note each Web Block number as key with it's CurrentRowNumber as value. Everytime I delete or add a table, I update the mapping manually. 

Then, when a Web Block is making changes, it sends it's JSON string with its own (unique) number as a message to the parent. The parent can then check in the mappin which row number needs to be edited. That's it!

Solution