Skip to main content

Is there any better way to check if a value is NOT in a list?

90% of the time, when I’m checking a value against a list, I want to check if the value does NOT exist in the list.

 

Is there any better way to handle this?

I’m currently doing the following.

And then the rest of the tasks are after this check.

I’d ideally like to have a step if value does not exist in list then continue.

 

@sleemand Just a thought… if you join all the values of a list into a string, it becomes somewhat of a CSV-encoded string. Then, if your values were unique enough, you could use an IF… String to see if the value is within the list.

Your values would have to be unique enough that a string search wouldn’t match another similar value.


That may work for my example that caused me to make the post.

In these cases, I’m actually starting with a comma delimited string and splitting that into a list for checking.

I never considered using the “Not includes” string comparison directly.

 

Like you mention, this wouldn’t work for times when I need exact value matching though.

Document Owner,Document Approver,Document Owner & Approver

 

For this string list, comparing “Document Owner” would match two values which is fine for what I’m doing currently.

If I wanted to remove “Document Owner” from the list, I could no longer use the string comparison method.


@sleemand The only other possible way of making that work would be to search for the string including the delimiter.

Instead of looking for “Document Owner”, look for “Document Owner,” with the comma in the search string. (You might have to append a comma to the string so that you could find the last value.)

Kinda hacky, but potentially faster than looping through the list looking for a value, setting a Boolean flag, etc.


Yeah, that sounds like using the SQL charindex function where you wrap the source string and the search string in the delimiter for an exact match regardless of position.

,Document Owner,Document Approver,Document Owner & Approver,

Then compare ,Document Owner, which would still function as expected if the list ever changes.

It isn’t a huge deal and seems like 6 of one, half a dozen of the other in terms of the cleanest way to handle it.