Multiple attributes sort on ListSort

Multiple attributes sort on ListSort

  

Hi.

How can I sort by multiple attributes on ListSort System Action?

I know that SortRecordList Extension could do it.

(Eg: "Entity1.attribute1,Entity1.attribute2,Entity2.attribute")

But I think ListSort has advantage because of the 'By' parameter is Genelic Type.

So we can change attribute name easier.


Best regards,

Hi Naomichi,

There is one solution, but it's not the best performance-wise.

You can run the ListSort action several times and everytime use the previous action output as input, but make sure you run the last order first.

Kind regards,

Remco Dekkinga

Hi Naomichi Baba,

   Why you are not creating dynamic order by  .you can pass the order by parameter dynamically.



Thanks

Rajendra Singh

Hi Remco,

Thanks for your reply.


As you mentioned, I tried to run the ListSort action several times.

(Note that, the ListSort action doesn't have any output parameter, so I put the same list to each input parameters.)

But It didn't work expected.

The list was sorted only by last run attribute and unsorted by other attributes.

Look at the result picture of my sample program, which I attached.


Regards,

Hi Rajendra,

Thanks for your reply.


In my understanding, dynamic order by is used in Aggregate.

But for example if we want to sort record list which sourced from JSON or Excel or input by users, I think we cannot use it.


Regards,

Naomichi Baba wrote:

Hi Remco,

Thanks for your reply.


As you mentioned, I tried to run the ListSort action several times.

(Note that, the ListSort action doesn't have any output parameter, so I put the same list to each input parameters.)

But It didn't work expected.

The list was sorted only by last run attribute and unsorted by other attributes.

Look at the result picture of my sample program, which I attached.


Regards,


Hi Naomichi, can you repost your attachment? I only see a bouncing ball with the text Processing Upload...


Hi Remco, thanks for notify to me that.
It seems there is something problem to attach a file.
I'll insert the image inline.

Hi Naomichi,

I'll dive into this issue and see what I can create. 

Kind regards,

Remco

Solution

Hi Naomichi,

Effectively ListSort sorts the whole list according to the criteria in By, so applying it multiple times will undo previous sorts and only consider the last one, since the underlying sorting algorithm is not stable.

Now, since you can write any expression in By, depending on the scenario you are able to produce an expression that uses all the attributes and achieves the sorting you want. In particular, if all your sort attributes are Texts with no spaces, like the case of Currency and Color, you can sort by both using an By expression Currency + "|" + Color.

Other data types are not so safe. For instance, if you had an integer Quantity attribute and used the same technique, it would be converted to a Text and the sorting order would be different. Say, if we had a list with the values 10, 2, 1 for Quantity and we sorted it By:

  1. Quantity, would result in: 1, 2, 10
  2. IntegerToText(Quantity), would result in: 1, 10, 2

I think that in the case of Dates, the sorting order is the same after converting to Text, as long as the 0 padding is kept for months and days (i.e. 2017-01-02 is ok, while 2017-1-2 is not).

So, bottom line, for that particular scenario you should be able to use the By expression OrderDate + "|" + Currency + "|" + Color.

Regards,

Paulo Ferreira

Solution

Hi Paulo,

I solved the issue. Thank you very much for reply!