Comparing two Collections and and saving unique values.

Skauby

New Member
Hi,

I'm new to both coding and Blue Prism and i'm looking for some support.

I have a a project were I need to compare data from two collections ("Collection_1" and "Collection_2") and pick out any unique rows from "Collection_1" and save in "Collection_3".

Both collections only consists of one column which contains a Service ID.

I've tried with a standard Loop within a loop in BP, but since "Collection_1" and "Collection_2" both consists of over 22000 rows this is too slow.

I've looked around on different forums and it seems that my best bet for speed would be to create a code stage in an object that does this, I could really us some help in creating a code either in VBA or C# to do this.

I know it's a big ask, but any help would be appreciated.


Example:

"Collection_1"
Header: Service ID
4567
4566
4532
3455
9989
4312

"Collection_2"
Header: Service ID
4561
4562
9989
4312
4532
3455

Output:
"Collection_3"
Header: Unique Service ID
4567
4566
 

Skauby

New Member
I still haven't found a good solution for this so if there's anyone out there willing to help I would be grateful! :)
 

sahil_raina_91

Active Member
I still haven't found a good solution for this so if there's anyone out there willing to help I would be grateful! :)
Make sure to add below 3 Namespaces in Code Options Section :
System.Data
System.Collections.Generic
System.Linq

Make sure to add below 2 External References in Code Options Section :
System.Core.dll
System.Data.DataSetExtensions.dll

1619796383179.png
Create a code stage with Collection_1 & Collection_2 as inputs, & Collection_3 as output:
CODE(Yes, a single line is enough) : Collection_3 = Collection_2.AsEnumerable().Except(Collection_1.AsEnumerable(), DataRowComparer.Default).CopyToDatatable()

1619796435799.png
 
Last edited:
The above solution is correct, but it is not generic, if the columns are identical you can give a merge collection or an append of collection_2 to collection_1 and then you can use remove duplicates, so you can use as many collections as you want
 

sahil_raina_91

Active Member
The above solution is correct, but it is not generic, if the columns are identical you can give a merge collection or an append of collection_2 to collection_1 and then you can use remove duplicates, so you can use as many collections as you want
That would be an incorrect solution, besides the fact that it would take more time to execute.
Merging & removing duplicates will fetch all unique records from both collections. OP only wants unique values present in 1st collection that are not present in 2nd collection.
 
Top