How to check if all Dictionary bool items are False?

I have a Dictionary (String, Boolean) with a bunch of items added to it as either True/False. I want to check if all the items = False then my automation should throw an exception. These bools are flags for checkboxes the robot selects and if all are unselected, the submit button is greyed out and cannot continue, so I’d rather throw an exception earlier on as soon as we know if everything is set to false then throw exception.

I am looking for the cleanest way to do this. I realise I could possibly loop through the dictionary using For Each and then if item=True flag this and break from loop.

Is there a simpler way to check this?
… Basically want something simple like If myDictionary.Keys.Contains(True) THEN continue ELSE throw exception

hey,
you can follow this workflow


where Dictionary is a variable of Dictionary(of string,Boolean)
Thanks

Hi @Jon_G ,

You could Check with the below Expression if all the values are False or True :

yourDictVar.Values.All(Function(x)x)

The above should return true if all values are true.

Let us know if this isn’t the expected answer.

Thanks so much, this is exactly what I’m after.

What would be the inverse for this, to return True if all values are False?

1 Like

@Jon_G ,

You could simply add a Not operator :

yourDictVar.Values.All(Function(x)Not(x))

Perfect - thanks heaps!

Am interested to learn more about the significance of the “x” in Function and how this method is designed exactly, where can I find documentation on this?

@Jon_G ,

There are many tutorials on the Linq methods, Maybe for a Starter, You could go through the below :

Thanks very much for the solution and also sharing these resources. Will have a read through and try to learn more LINQ stuff :slight_smile:

1 Like

Hi @Jon_G,

You can get support from extensions while writing methods.

Regards,
MY

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.