11
Views
3
Comments
Solved
[SortRecordList] Current value is wrong after sorting
Forge component by Ivo Gonçalves
23
Published on 18 Dec 2020
Application Type
Traditional Web

Hi,

I have use case where I have written a small application which gives back a list of structure (SelectedUnits in the image below) and at the end, I sort the computed list by differenceValue and length ascending. Now the problem is I was only interested in first one and was using SelectedUnits.current to refer to top most value but apparently there is a bug in the SortRecordList component because of which 0th element is not the current element.

Regards.

Recurssion.oml

mvp_badge
MVP
Rank: #2
Solution

Hi Prasad,

This isn't a bug. The Current can only be relied on to be a specific record in a limited number of cases:

  • After a query (Aggregate or SQL), the Current is equal to the first record in the output list (that is, index 0);
  • Inside a For Each, the Current is equal to the record that can be indexed by CurrentRowNumber;
  • In a Screen Action after clicking on a link inside Table Records or List Records, the Current of the Widget's List corresponds to the Record of the clicked line.

In all other circumstances, including after a For Each, when receiving a List as Output from an Action, after passing a List to an Action and in an Exception Handler that was triggered from inside a For Each, the Current is undefined. This is by design, so it isn't a bug.

What happens in your specific case, is that in order to Sort a List, the SortRecordList Extension needs to move items around, which by definition changes what the Current record is. That said, the Extension could reset it to the first item, but it's not a bug that it doesn't do so.

As Jeanene already wrote, you can access the very first record by indexing the List with an index of 0.

Champion
Rank: #275

The "Current" record will most likely have changed because of the sort logic so maybe a "bug" yes. But in the meantime if you are only interested in the first record then you can access it specifically as SelectedUnits[0] rather than SelectedUnits.Current .

Remember to check that the list isn't empty though before trying to access the record or you may get an exception.

Rank: #111

Hi,

That is what I am doing now but wanted to report this bug so that component team is aware and others using the component is aware of this.

Regards.

mvp_badge
MVP
Rank: #2
Solution

Hi Prasad,

This isn't a bug. The Current can only be relied on to be a specific record in a limited number of cases:

  • After a query (Aggregate or SQL), the Current is equal to the first record in the output list (that is, index 0);
  • Inside a For Each, the Current is equal to the record that can be indexed by CurrentRowNumber;
  • In a Screen Action after clicking on a link inside Table Records or List Records, the Current of the Widget's List corresponds to the Record of the clicked line.

In all other circumstances, including after a For Each, when receiving a List as Output from an Action, after passing a List to an Action and in an Exception Handler that was triggered from inside a For Each, the Current is undefined. This is by design, so it isn't a bug.

What happens in your specific case, is that in order to Sort a List, the SortRecordList Extension needs to move items around, which by definition changes what the Current record is. That said, the Extension could reset it to the first item, but it's not a bug that it doesn't do so.

As Jeanene already wrote, you can access the very first record by indexing the List with an index of 0.