How to Compare two Collection variables

  • 22 February 2017
  • 9 replies
  • 56 views

Badge +5

I have two collection variables that looks similar to this:

Collection 1: A, B, C, D, E, F, G

Collection 2: B, D, F, G

Desired Results for Collection 3: A, C, E

In the third collection, I need to have all of the values that are NOT in Collection 2 - comparing the values against Collection 1.

Collection 1 is a complete list of departments. Collection 2 is a list of departments that have submitted a request. Collection 3 should be a list of departments that have NOT submitted a request. 

I know this should be possible and I know i will have to use a Collection Operation. I'm just not sure how to set it up properly. Any help would be AWESOME!


9 replies

Userlevel 5
Badge +14

nintex doesn't provide action that would operate on whole (multi)sets. you will have to do looping.

for smaller collections (data sets) it might be doable, but for bigger ones you might hit performance issues.

you do not specify how/where do you populate collections from. but it might be much more efficient if you could filter dataset already when reading it in from source.

anyway, to make it with collection, the best would be to use 'remove by value' operation.

- first, determine which collection have less elements

- loop through that collection

- within the loop, 'remove by value' current loop's element/value from bigger collection.

- at the end you should end up with collection of elements that were present in bigger collection but not in smaller one.

Badge +10

Try this, combine collection 1 and 2 (convert collection 1 and 2 to a string, concantenate , split for semi-colon using regular expression), and use the collection operation remove duplicates.

I haven't tried it, hope it works

Userlevel 5
Badge +14

this is not going to work - 'remove duplicates' removes all but one instances of a given redundant element.

so you will end up with a collection that contains one instance of every element that appeared in either source collection.

Badge +5

Use the loop action or the for each action? What would be the conditions for the loop action?

Userlevel 5
Badge +14

ForEach is designed right for iterating through collections.

Badge +10

Ya, that's right. But I think regular expression can remove duplicates.

Userlevel 5
Badge +14

good idea.

if we assume sorted union of both collections then I think it could be doable with a regex

Badge +3

I think the best way is to use the "for each" action to iterate it for each value in collection variable 1. Within the "for each" action use a regular expression (check match) if value x of collection variable 1 is part of collection variable 2. The Boolean of the check match action returns the value Yes or No.

Now you can collect all values with Boolean value "no" !

Userlevel 5
Badge +14

Hi ‌,

does any of provided suggestions meets your expectation?

if so, please mark the one correct answer so that the topic is closed.

#BRGreview

Reply