How to use String Operators in a Case of a Switch Activity

I have scenarios where i want to use string opperator like StartsWith or Contains and also logical operators inside a case of a switch activity

Hi @indiedev91 ,
Can you share input and expect output?
regards,

image

in expression write condition
then in add activity you can use the activities for the process
and if you want to use new case click on add new case\

Hope it helps
Usha

Its not a comlicated thing , i just want to understand is there any way we can use string operator

for eg

for each (currentItem in dataList){

Switch (currentItem){

    Case1 : String.StartsWith("EMPCRN") : Message Box

}


}

if it is too much complicated to implemen i can use else if conditiions , i have barely 4 conditions right now to check for , i thought i should try switch case for test purpose , but didnt able to figure out how can i do this with case

StartsWith or Contains along with logical operators inside a case of a Switch activity by using expressions in the condition field of each case

  1. Create a Switch Activity: Drag and drop a “Switch” activity into your workflow.
  2. Define Cases: In the “Cases” panel of the Switch activity, add the different cases you want to evaluate. For each case, provide a unique value or identifier. These are the values you will compare against.
  3. Use Expressions in the Condition Field:
    example for a “StartsWith” condition
textVariable.StartsWith("Prefix")

example for a “Contains” condition

textVariable.Contains("SubString") 

@indiedev91

you can try this

@indiedev91

you are trying to say that i add conditioion itself in the expression , if yes its not helpfull in this scenario , im looping through a list of string and checking the currentItem

Hi @indiedev91

  • To check if a string starts with a specific substring:

condition: yourStringVariable.StartsWith(“substring”)

  • To check if a string contains a specific substring:

condition: yourStringVariable.Contains(“substring”)

  • Here’s a sample :
  1. Switch Variable
    Case yourStringVariable.StartsWith(“substring1”):
    // Activities to be executed when the string starts with “substring1”

  2. Case yourStringVariable.Contains(“substring2”) And anotherVariable = 42:
    // Activities to be executed when the string contains “substring2” and anotherVariable is equal to 42

  3. Case Else:
    // Default activities to be executed when none of the above conditions are met

For Each currentItem In dataList
    If currentItem.StartsWith("EMPCRN") Then

       MessageBox.Show("Starts with EMPCRN")

    ElseIf currentItem.Contains("SomeSubstring")   Then

        MessageBox.Show("Contains SomeSubstring ")

    ' Add more conditions as needed
    End If

Next

@indiedev91

@indiedev91

Basically expression part can be mentioned on top level of switch activity to pass on value to respective cases and but not in each case

If I want add condition then you can mention in switch part itself like this

Cheers

Use Else If instead of Switch.

Hi @indiedev91 ,
“Switch activity” have type of argument
image
→ with string case operators we have boolean value
in your case, I think we should use "if else " activity


regards,

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