Hello,
I have read the documentation of the activity ‘Switch’ and know that I have first to define the type of input.
For my needs I select “string”. Now I want to iterate with “ForEach” over an array of strings.
The result is this:
At this point I run into a problem. I can use a default value at this point but I cannot use a variable that I want to be evaluated and the value of the variable compared to the string value.
As far as I know until now I have to know every value that can occur at this place first before I can use this activity.
May be that I’m missing something, but can someone show me a solution to the problem?
Thanks for your answer. Yes, I can use this as workaround.
But in my opinion this is activity is not complete and can only be used rudimentarily.
For example: In C# it is defined that each case label defines a pattern that is compared to the match expression. This means that in C# it is possible to use complex objects at that point. I don’t want to ask for this entirely, but a little bit more flexibility would be welcome.
What is the best way to make this issue more known? 2 years later and this recommended change to make the switch statement more robust by providing the ability to use variables in cases has still not been made.
Giving the flexibility to add variables to switch case would have lots of sense. Curious to know if there is any technical limitation on why UiPath is not considering this
I am trying to wrap my head around this scenario but I am not able to find the usefulness/how it make sense to use variable for case. Why cant you use ElseIf here ? which according to me should be used.
In @Yoichi solution, even though switch value is dynamic but cases are fixed (0,1,2 etc.) in this scenario. Like if case1 comes which is linked to say 0 likewise for case2 and case3 all the linked values of all the possible cases should present in switch case. So, instead of using the switch case why not use the elseif here.
Can someone please explain to me how using variables in cases can help in specific scenario. Possibly with examples.
This will never get fixed or implemented I think.
Its simply not how the case/switch function works and its a .NET thing from Microsoft.
What we are seeing is the low code front end used to configure a Switch/Case statement in .NET code. That code requires all the cases be known at design time / compile time because the case statement gets compiled into a optimized ‘jump table’ or lookup thing that works super fast. Its simply does not allow the behaviour you ask for.
The activity would have to be completely rebuilt so that its no longer actually a Switch / Case and builds the logic differently somehow and thats completely pointless cause you already have that functionality available to you in an Else If, so use that.