Unique Items in a collection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
13-06-19 04:57 PM
Does anyone have an existing activity or some VB code I can use to filter a collection to only include unique items?
Thank you 🙂
------------------------------
Oliver Mohajeri
Consultant
EY
Europe/Zurich
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
14-06-19 10:01 AM
------------------------------
Łukasz Janiak
RPA Developer
Nordea
Europe/Łódź
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
14-06-19 01:01 PM
I made an action in BP that does not use any custom code stage, but it's a bit convoluted because I have it accounting for any collection of any number of fields and gives the choice to deduplicate based on one or more fields. This kind of manipulation is likely better in code as you mentioned. But, to solve at least your use case, it's not very difficult to do in BP.
First, I'll assume you're trying to filter a collection for unique values in a single field. The most efficient way that I am aware of is to first use Sort Collection on the field you are focusing on. Then, use Loop stages to loop through the collection. Also, create two data items: Current Value and Previous Value.
Here's the flow or at least this is something like what you'd go for.: (Collection1 is your main collection and Collection2 is what you're copying unique values to)
Sort Collection1 on your field so that equal values are next to each other alphanumerically.
Loop Start
Get the current value of the field and store it in 'Current Value'
Decision stage: [Current Value]=[Previous Value]. (FYI: the first time through the loop it will compare the current value to empty text -- if this is a text datatype)
If Yes, Go to the Loop End
If No, add a new row to Collection2 and store the current row in Collection1 into the new row in Collection2
(still under If No) Also set the value in [Current Value] into [Previous Value]
Loop End
If you are trying to compare the entire row, there are a couple ways to do this. You can compare entire collections like [CollectionA]=[CollectionB] so you'd probably copy rows out into temporary, single row collections to compare them to each other. Otherwise, depending on the datatypes of your fields, you could compare a concatenation of all the fields, like [CollectionA.Field1] & [CollectionA.Field2] = [CollectionB.Field1] & [CollectionB.Field2].
------------------------------
Dave Morris
3Ci @ Southern Company
Atlanta, GA
------------------------------
Dave Morris, 3Ci at Southern Company
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
14-06-19 03:29 PM
Here's some C# code I wrote to pull distincts. Should be easy enough to convert back to VB.
Inputs:
Collection - Collection
Column - Text
Outputs:
Sorted Collection - Collection
DataView dv = Collection.DefaultView; Sorted_Collection = dv.ToTable(true, Column);
------------------------------
Ami Barrett
Lead RPA Software Developer
Solai & Cameron
America/Chicago
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
17-06-19 10:05 PM
As previously mentioned, it's relatively trivial to create an object to loop through the input collection to retrieve unique values. I've included an action I created for this very purpose though I wouldn't suggest using this on large collections.
------------------------------
Oliver Ong
Consultant
Ernst & Young LLP
America/Edmonton
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-06-19 11:33 AM
Dim v As New DataView(Collection_In)
Collection_Out = v.ToTable(true, Column_Name_CSV.Split(","))
Note however that the output collection will only contain the columns you have specified, so this may not be exactly what you're after.
------------------------------
John Carter
Professional Services
Blue Prism
Europe/London
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-10-20 03:04 PM
This works well with VB but When I change the code to C# , I am getting compile error with the Split function. Can you please assist with the corresponding C# solution?
------------------------------
Kirtish Trivedi
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-10-20 03:22 PM
DataView v = new DataView(Collection_In);
Collection_Out = v.ToTable(true, Column_Name_CSV.Split(','));
------------------------------
Ami Barrett
Sr Product Consultant
Blue Prism
Plano, TX
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
30-10-20 03:05 PM
------------------------------
Nilesh Jadhav
Senior RPA Specialist
ADP
India
------------------------------
Consultant
ADP,India