Switch based on contains


#1

Hello,

I am trying to pass an URL to a Switch activity in order that if it contains : facebook it should run an activity , if it contains twitter it should run a different activity, etc.

But i am having issues with syntax.

image

can anyone help me develop a solution for my case?


How to pattern match the string
How to pattern match the string
#2

Hi,

So Switches are slightly different than Decisions or If statements. The Cases should equal an Integer or String that the Expression returns (if that makes sense). The Expression should return exactly the string you are going to use as your Case so for example “facebook”.

In order to use .Contains, you can simply put that in the Expression. For example,

Expression:   If( row("URL").ToString.ToUpper.Contains("FACEBOOK"), "facebook", If( row("URL").ToString.ToUpper.Contains("TWITTER"), "twitter", "default" )

Then your cases would just look like:

Case1 facebook
Case2 twitter
Case3 default

I would also recommend using this in a Flow Chart, but that’s my opinion.


You can also consider State Machines. They allow you to use a full condition for the destination of each platform, that is, if each one uses a different process.

Regards.


#3

switch.xaml (6.5 KB)


#4

Hi Clayton,

what will be the condition for the states?


#5

Hi, what do you mean by your question @PriyaRK?
The conditions go in the Destinations part of the State, and you can put anything there that returns a boolean like text.Contains(“abc”), et cetera. When the State that processes is complete it will look at which destination to take in the order from top to bottom as they are listed in the Destinations section, and only if it is True.

Regards.