Switch case using String value in UI-path

Hello All,

I just want to explore 4 case in Switch. Saved as ShortDesc variable some text. If ShortDesc having doesn’t have any key word should choose case 1. If ShortDesc have “Strike 1” should choose case 2. If ShortDesc have Strike 2 should choose case 3. If ShortDesc have Strike 3 should choose case 4.

I need to operate Switch case as if shortdesc have keyword. SwitchCase

1 Like

Hi @Raina_Mani

Use Short Desc=String.empty in default

Case 2 ShortDesc=Strike 1

then do the manipulations like that for other cases

Thanks
Ashwin S

1 Like

Hi @Raina_Mani,

I think we cant give expressions/variables in cases.

switchCase.xaml (15.1 KB)

Try this defined for your scenario.

Thanks!

@Raina_Mani:
Kindly try the below steps:

  1. Assign the Strike value eg:Strike 1, Strike 2,… to a variable. I think it is ShortDesk in your case.
  2. Expression: ShortDesc TypeArgument: String
  3. Case: Strike 1 (No double quotes here)

Hope this helps.

You can most definitely use the UiPath Switch activity with a String.

They key is to change the TypeArgument to String in the switch activity’s properties window.

UiPath Switch Expression Types

You’ll notice that the UiPath Swtich Activity works with int32, String, Object, array and in fact, any type you can browse to.

Just make sure all the types match up, both in the expression and the case. And in the case, leave out the quotes, otherwise the case will mess up. It’s one of the few cases in UiPath where a String is not double quoted.

Get UiPath Certified

1 Like

Unfortunately, there is no way to do what you want using a Switch, since you cannot put an expression into the Case. You’ll have to use multiple If activities.

They don’t have to be nested. I see people do this a lot and it’s unnecessary. Just do consecutive If activities…

If ShortDesc.ToUpper.Contains(“EXAMPLE 1”)

  • do something

If ShortDesc.ToUpper.Contains(“EXAMPLE 2”)

  • do something

If ShortDesc.ToUpper.Contains(“EXAMPLE 3”)

  • do something

etc…

@Raina_Mani
We can do this using If condition within Switch case. Please find the below statement & snapshot and let me know if it is working for you
if(string.IsNullOrEmpty(ShortDesc),“Case1”,If(ShortDesc.Contains(“Strike1”),“Case2”,If(ShortDesc.Contains(“Strike2”),“Case3”,“Default”)))

2 Likes

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