Example Dictionary =
{Sweden, Nordics}
{Finland, Nordics}
{Denmark, Nordics}
Variable = Sweden
if Variable in Dictionary, Print Value
Expected Output = Nordics
Example Dictionary =
{Sweden, Nordics}
{Finland, Nordics}
{Denmark, Nordics}
Variable = Sweden
if Variable in Dictionary, Print Value
Expected Output = Nordics
Unfortunately, the âSequenceâ feature on UiPath does not include Microsoftâs âKey Existâ action. âKey Existâ is only available for Flowcharts.
Hello,
Canât you use contains ?
Seems that it has a containsKey method, maybe it can work ?
Yes, I used this: IF Dictionary.ContainsKey(Country), Message Box Prints Dictionary.Value(Country)
What if I want to take it to the next step and compare the Value to another variable?
IF Dictionary.Value(Country) = Nordics then proceed with next stepsâŚ
Maybe i donât understand but if you want to iterate you can do a For each activity and then for each item in your dictionnary you can put your conditions and your actions.
But if you do that you can just do item.key or item.value to know the key or the value
You can do YourDictionary(Key) to obtain the value. Maybe it was your question, sorry for the precedent answer if it donât help you at all ^^â
To clarify, Iâd like to do two checks.
Check 1
Check 2
Donât think I need to iterate in a for loop here?
if YourDictionary.contains(âSwedenâ) then
{
if YourDictionary(âSwedenâ).equals(âNordicsâ) then
{
â Continue
}else{
â Terminate
}
}else{
â Terminate
}
Nope, you basically wrote down your own solution there. Just a regular sequence.
Keys are unique in a dictionary.
BINGO! This was the one I was looking for. Thank you so much @Constant_Roux. Bless you.
Surround it with try-catch. Otherwise if âswedenâ doesnât exists in your dictionary it will throw an exception.
Hi Rene, thanks for the recommendation. Do you mean I should use trycatch instead of an IF statement in the Sequence Activity?
The if statement should be surrounded by an try-catch. (Right click on the if-activity and lookup for âsurround with try catchâ)
So if your dictionary contains âswedenâ and the region is equal to ânordicsâ you want to do something and if the region is not equal to ânordicsâ you want to do something else.
But when there is no entry equal to âswedenâ in your dictionary you want to catch the exception and follow up with another activity e.g. send an email to someoneâŚ
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.