Multiple Cases in switch Case

Hi Uipathians,

I am trying to use multiple cases in a switch case activity for strings. However the usual syntax of adding a comma between the cases does not work as it now recognises the case as the full list.

e.g.

switch on item

case A,B,C,D

only searches for the case “A,B,C,D”

What I want is to be able to put multiple case values in so that I can reduce the amount of code i write.

I could write an if statement utilising a load of OR conditionals but this is messy and hard to debug.

I can’t find any information on separating the case values within UiPath. standard syntax for vb.net is to use a comma.

Your help is most appreciated.

1 Like

Hello!

There’re two ways of doing a switch on Uipath.

First, with Flow switch
image

Second, with Switch
image

I think that is not possible to separate all the cases on a unique line. But let’s wait for someone else to answer :slight_smile:

Regards,

5 Likes

Hi Lucas,

Thanks for the reply, if it’s not possible it lessens the use of Switch Case (in UIpath) substantially and would be a shame.

1 Like

In our java Coding we use multiple condition in Switch Condition like this…
case 1:
case 2:
case 3:<-Action->
break;

if suppose, the user input is 1 or 2 or 3, the <-Action-> will print because the break will not mention in the previous condition…

But in UiPath BackEnd Coding, the developer will mention the break condition for all the case…

So, In UiPath the multiple condition in switch case will not possible

4 Likes

Hi,

Thanks for replying,

I’ll suggest this to the devs then as it is entirely possible within vb. net so should be possible within the studio.

Thanks

Hey @jakelewis18

you can use invoke code activity for the same within studio :slight_smile: i guess.

Regards…!!
Aksh

2 Likes

In our production environment we are currently running the pre moonlight update but I will certainly keep that in mind when we update.

Thanks

Gotcha… unfortunately i have also updated to latest one but still will see it in some free times :slight_smile: and will get back to you if will found something interesting :slight_smile:

but from my inner feelings these person might have some good views on this.

They are really doing great and they are haviing a great knowledge storage disks :stuck_out_tongue:

@andrzej.kniola @Florent_Salendres @ClaytonM @sfranzen

2 Likes

Hi,

It looks like a limitation of Windows Workflow Foundation and its Switches activities (Made by Microsoft and not UiPath).

I would see several workaround which could visually simplify how the approach would look that will be highly dependent on the problem you need to solve (ex: if it’s complex due to the number of different value to be check against or rather due to the number of path you would take). If you could be sharing less general problem that you are encountering that would be helpful to propose you solutions.

One example of construct which can be writen quite fast and is easy to read:

{"January","February","March","April","May","June"}.Contains(strMyVal)

This would need to be place in a flow decision or a if as condition.

Cheers

3 Likes

Hi Florent,

That could indeed be a workaround. Our problem is that we have 34 fields which, based on their value, need to be filtered into different collections based on their value. We only have 3 collections so a switch case based on multiple values seems ideal. and flexible for further cases.

I’m out of my depth in terms of my knowledge of Windows workflow so apologies but is their scope for this to be coded in?

thanks for your help.

Assuming that by field you mean variable, i would then definitely go for An invoke Workflow having your logic workflow inside and the field as argument. You would call this Logic Workflow for each argument (using a For each if it is possible) and also your 3 collections (Passing them should not be an issue in term performance since Collection in .Net are reference types)

Inside the logic workflow i could have a flowchart passing trough 3 Flow decisions having the logic for the value.

Those three follow decision on True could have an add to collection activity depending on the condition met.

It should not be necessary to return those collection at the end of the workflow since, once again, they are reference type. Simply explain what you are passing is not the collection itself but their coordinate in the memory. Collection inside workflow and outside are effectively the same.

I could make you an example on this later if you want.

Hope it helps :slight_smile:

Being pre-moonlight, Regarding WWF you could make an add-hoc Custom activity if you feel like it is worth it.
Using the search function of the forum you should not have issue finding explaination on how to create it.

Cheers

2 Likes

Hi,

Florent is right. The specific issue is that case values are interpreted as literals, in other words the value is directly interpreted as whatever the TypeArgument is. This is more restrictive than Visual Basic and is the reason why you can’t use the workflow activity with as much freedom.

However, you may be able to use a State Machine workflow to get something closer to what you want. You can have multiple transitions from one state to one or more others, each of which can have a different associated condition, perhaps in the form of a Contains statement as suggested by Florent.

Edit: Note that this is more or less an abuse of the state machine format and there is one tricky part to this: if none of the conditions are true, then the workflow will never leave its current state nor halt. This is because this type of workflow is designed to wait for triggers and/or conditions to occur. A real example would be an application at a certain screen, where the actions performed in the corresponding state’s Entry part cause a window to pop up. The trigger could be a Find Element on a generic dialog, with various transition conditions depending on the message displayed.

3 Likes

Thanks

1 Like

I have a lower problem that I can’t change the case value,so anyone can help me ?please

I find!