How to use variable as the case of "switch activity"

I am trying to use switch activity for case VarA, VarB and VarC inside switch activity but it not working. Please advise on how to achieve the following result.

Assign Var A = “Apple”, Var B = “Banana”, Var C = “Cat”
Assign Var D = “Apple”

*** I am using Var A,B,C,D as I want to make the case dynamic

Switch: Var D
Case: Default —> write 0
Case: Var A → write 1
Case: Var B → write 2
Case: Var C → write 3

I want the answer to be “write 1” instead of “write 0”.

1 Like

Hi @RoboticKK
you can do like either that you can pass the variable as expression and value as case

But when you try to pass the variable to case it wont work buddy as CASE CAN ONLY TAKE OBJECTS, NOT VARIABLES…
this could help you

even if you try you will get like this

Cheers @RoboticKK

1 Like

I’d switch it around if I were you.

Have the Switch as a variable which could be any of the items (Apple, Banana, Cat)

Then each case in the switch would be:
Default → write 0
Case: Apple → write 1
Case: Banana → write 2
Case: Cat → write 3

Don’t forget to change the switch properties TypeArgument to String

The situation is both the switch expression and the case are variables

Hi there,

Slight correction to everyone’s answers here…

I have found that as the type argument is changed to string that is being passed in every case, you will have to give Apple, Banana and Cat without the quotes. here you go :slight_smile:

And the workflow for your reference : Main.xaml (5.3 KB)

Hope this solves your query



Oh my you are a GENIUS! Saved me over an hour of headaches trying to figure this out. THANK YOU! :slight_smile:

1 Like

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