126
Views
4
Comments
Solved
[SortRecordList] Current value is wrong after sorting
sortrecordlist
Service icon
Forge asset by SortRecordList Team
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
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
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.

2017-12-13 08-27-28
Joey Moree

I'd like to expand on this when you say "That said, the Extension could reset it to the first item, but it's not a bug that it doesn't do so. "

However trying to do a reset of the current does not seem to be working.
The current remains to be bugged.
I made a quick example to sort a list [2,1,3,4] ascending.
It sorted to [1,2,3,4] however the current remained on "2".
When doing a sort for the second time (descending) the list turned out as follows:
[4,3,2,2] by being unable to set the current to the actual first element when returning the list to outsystems, any successive sorts will break the list.

That being said, the ListSort from Outsystems does not seem to be doing this.


UPDATE, apperantly has to use RecursiveReset() to reset rather than using the Reset() method.


2021-04-21 23-06-46
Jeanene Williams

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.

UserImage.jpg
Prasad Rao

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.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
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.

2017-12-13 08-27-28
Joey Moree

I'd like to expand on this when you say "That said, the Extension could reset it to the first item, but it's not a bug that it doesn't do so. "

However trying to do a reset of the current does not seem to be working.
The current remains to be bugged.
I made a quick example to sort a list [2,1,3,4] ascending.
It sorted to [1,2,3,4] however the current remained on "2".
When doing a sort for the second time (descending) the list turned out as follows:
[4,3,2,2] by being unable to set the current to the actual first element when returning the list to outsystems, any successive sorts will break the list.

That being said, the ListSort from Outsystems does not seem to be doing this.


UPDATE, apperantly has to use RecursiveReset() to reset rather than using the Reset() method.


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