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.
can anyone help me develop a solution for my case?
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,
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.
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.
Depending of your use case, you might find handling the different cases in a mapping structure convenient. That way, you don’t have to edit your code if any change occurs but just udpate the dictionnary/datatable/worksheet/…that contains your mapping and add eventually related workflow.
ForEach ThisCase As KeyValuePair in MyCases
If row('url').ToString.Contains(ThisCase.Key)
ThisWorkflowPath = ThisCase.Value.ToString
Break
InvokeWorkflow(filename=ThisWorkflowPath)
You can use a default value for ThisWorkflowPath too (beware of its scope). You have the idea.