[WEB] Dynamic sorting with ListSort component

[WEB] Dynamic sorting with ListSort component

  

Hi,


So here I am again, retrieving a list of items from a REST Service and let's say I can only sort the list on the client side (Outsystems, of course ) but as this is not stored on OS' database/entities there is no way for me to use built-in dynamic sort stuff so the only sorting tool left is ListSort component.

What I've been trying so far is to set a condition to sort the list according to the value of the variable "Sorting". So that, if the value of Sorting is "Name", the retrieved list will be sorted by Name, and yes, I made sure that every single text value for Sorting is an existing field of the items contained on the list.


Thank you by advance.


https://imgur.com/a/qc8tL


Jordi.



Solution

Hi Jordi,


Just by looking at your printscreen, i'm not quite sure if you have defined either P... or dni, but at first glance i suggest you to fix your If condition:


If ( Sorting = "P...",  P... , If ( Sorting = "Dni", Dni , Date ) )


Cheers

Solution

Hi Jordi,

Service Studio is complaining because your If() functions are returning Text values, and you're trying to use an or operator that must have as operands two Booleans.

What I believe you want/need is chained If() functions:

If(Sorting = "...", SomeField, If(Sorting = "???", SomeOtherField, AThirdField))

André Rodrigues wrote:

Hi Jordi,


Just by looking at your printscreen, i'm not quite sure if you have defined either P... or dni, but at first glance i suggest you to fix your If condition:


If ( Sorting = "P...",  P... , If ( Sorting = "Dni", Dni , Date ) )


Cheers

Hi André,


Your solution seems to be working fine. Actually, I needed 4 conditions so yeah, I took your answer as a base and went ahead from that, it's now sorting as I wanted it to so thank you.


Thank you too, Jorge!


Jordi.