1544
Views
2
Comments
Easy to sort a list

Hi,

I am working on an environment which is v10.0.320 and I have a structure which has two attributes as below and a variable with list of that structure

  • Amount, a decimal field
  • Length, a integer field

Now I want to sort this variable based on amount field in descending order and length in ascending order (basically highest amount with least amount in length). Do we have any component that can do this?

Regards.

2021-07-14 09-27-33
Luís Cardoso

Hello Prasad,

You can use ListSort action from (System).

You need to use it 2 times (pass the List and the order you want to implement): 


If this option does not work correctly, you can also use the extension SortRecordList

You can have more info about this extension on this post: https://www.outsystems.com/forums/discussion/21343/multiple-attributes-sort-on-listsort/


BR,

Luis

UserImage.jpg
Prasad Rao

Hi,

I started with ListSort and it was not working correctly because of decimal value and SortRecordList will work when both fields need to sorted in ascending or descending. I came up lot of hacks to this but none are true solution for example I ended up using converting the two value (1 as amount and 2 as length ) to a string with below expression and make isAsending as false in ListSort

FormatText(FormatDecimal(Amount,5,".",""),30,30,True,"0")+"|"+(9999999-Length)

As you can see here these value have upper bound but those upper bound are large enough for me to confidently say that it works for my usecase. I was just curious what if I had multiple amounts and various other datatype then I might end up with complex expression just so that it can sort properly and this will be unnecessary data prep operation before sort. 

It looks like this is the only way as of now

Regards.

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