List_SortColumn_GetOrderBy with Local List Variable

Hi everyone, hope you're doing great!


I'm running on a problem here that I could not find the solution. I have a Local List Variable, made of 5 different Entities (let's call Entity1, Entity2....). I'm trying to perform a ListSort using the value coming from the RichWidget List_SortColumn but for any kind of reason, the sort doesn't happen.


To extract the info from List_SortColumn, I'm removing the last 4 caracteres from the outcome of List_SortColumn_GetOrderBy, so the result is {Entity}.[Column]. This is the formula I'm using in the By field of ListSort:


Trim(Substr(List_SortColumn_GetOrderBy(Table.Id, "{Entity}.[Column]"), 0, Length(List_SortColumn_GetOrderBy(Table.Id, "{Entity}.[Column]"))-4))


The formula is correct as I could see during the debub, but for any kind of reason, ListSort is not understanding which column I want to sort by.. I cannot put this into my Aggregate, the way I created the code will not work (different query possibilities, all with this variable as the outcome).


Tks for any suggestions!!!

Hi Vinicius, 

If you are using ListSort, it does not use the same approach with the aggregate, I think. 

Take a look here in the solution, to see an example:

https://www.outsystems.com/forums/discussion/21343/multiple-attributes-sort-on-listsort/

I'm curious about why the sort in Aggregate does not work... 

Cheers

Eduardo Jauch wrote:

Hi Vinicius, 

If you are using ListSort, it does not use the same approach with the aggregate, I think. 

Take a look here in the solution, to see an example:

https://www.outsystems.com/forums/discussion/21343/multiple-attributes-sort-on-listsort/

I'm curious about why the sort in Aggregate does not work... 

Cheers

Hi Eduardo, thank you so much for your response.

The sort in the aggregate works, but the way my application works making the sort into one query would not make the job for me. I'm adding things to the list depending on different IFs and even though I have every query sorted, then I put them on the list they are not necessarily in order. That's why I want to sort them later using ListSort.

I looked for the link you provided me but my situation seems a little different. My issue is being like this:

If I directly select on the By field any {Entity}.[Column], the list sort works without any issue. But, getting {Entity}.[Column] from List_SortColumn_GetOrderBy doesn't work. I don't understand why it works if I select the column I want to sort by from the By drop down but if I type the exact same thing, it does not work...


I've made this work by putting a Switch, checking the column to sort coming from the RichWidget List_SortColumn and manually selecting the sort column in ListSort but this is very manual and every time I change my table, I have the rework in the action to adjust the sorting... Having it done dynamically would be much better...


Tks for your time!!!!

Solution

Vinicius, 

ListSort action is a system action and does not accept the attributes in the same format as the List_SortColumn_GetOrderBy returns. 

ListSort needs a static attribute, like Entity.Attribute, while the other returns {Entity}.[Attribute] as text. 

Take a look here: https://www.outsystems.com/forums/discussion/34940/listsort-vs-sortrecordlist-sort-by-passed-as-text/

The only way to do what you want with the ListSort is through a series of IFs. 

To do using a text, you need to use extensions, like the one that provides the SortRecordList action. 

Any solution has problems. So, if you can change your code to work with the standard sorting method in the aggregate (maybe we can help you with that?), you probably would be better. 

Cheers 

Solution

Tks Eduardo, I'll keep using the old method with Switch.


Tks.