cancel
Showing results for 
Search instead for 
Did you mean: 

How To Sort/Filter a collection based on conditions

RohanGoswami1
Level 3

Hi Team,

I need some sort of help to understand how to achieve this in code 
Suppose a i have a collection with fieldname Doc# which has 3 rows 1145202, 1005203, 1145204
I need to get the row which has highest last 2 digit in Doc# column. Can we do this via Sort/Filter collection or any other approach?

Regards
Rohan

5 REPLIES 5

LakshmiNarayan3
Level 6

Hi Rohan

This can be achieved by Linq in code stage

Use the below code 

OutColl = (From row in InColl.AsEnumerable() _
Order By Cint((row(FieldName)).Substring(row(FieldName).Length-2)) Descending Select row).CopyToDataTable

OutColl is output Colletion , InColl is input collection , FieldName is column name in which the sorting should be done this build for descending based on last two digits

if you think to make it more dynamic you can use variable for order and digits length

35405.png35406.png35407.png

Hope this is what you expected result

Also refer to https://community.blueprism.com/communities/community-home/digestviewer/viewthread?MessageKey=99472cf6-1d84-4d4b-9fc7-12186ba65599&CommunityKey=3743dbaa-6766-4a4d-b7ed-9a98b6b1dd01#bm99472cf6-1d84-4d4... thread for detailed steps of building

Regards

LakshmiNarayan3
Level 6

Attaching object with little more dynamic

Please let me know if this is working for you

Regards

RohanGoswami1
Level 3

Thanks for the Solution it is working fine. Is there any way we can do it through process? by not creating a object?

LakshmiNarayan3
Level 6

if you want to do without code stage then check this solution 

Add one more column the collection using utility - collection manipulation (Append Field)

 loop through the collection , use calculation stage (Right function) to set last two digits to added column

Once loop is completed - sort the collection with Sort collection action of utility - collection manipulation

Hope this helps you

Regards

RohanGoswami1
Level 3

Thanks for the Input at quick time. Doing in the same way.

Regards 

Rohan