You might be knowing that Switch statements are mainly used for Equals conditions. In this post, we will use the Switch Activity for contains text conditions.
Let us take an example of finding a word inside a sentence using switch activity. First, we assign the value to our message.
I am using an
assign activity. Declaring a variable
message and initializing with value “
Test case passed“. Let us define 3 possible message types –
- Test case passed
- Test case failed
- Some error occurred
You can change the types based on your project use case. Let us write an
if condition to fulfill this for the switch case. I have used nested if here.
Below is the syntax for the above if statement.
IF(logical_test, value_if_true, [value_if_false])
|logical_test (required)||The condition you want to test.|
|value_if_true (required)||The value that you want returned if the result of logical_test is TRUE.|
|value_if_false (optional)||The value that you want returned if the result of logical_test is FALSE.|
For more information about the usage of this function, refer to the Microsoft documentation.
Add a new Switch activity and give the if condition in place of the expression.
In the properties panel, change the argument type to
Add new case
Passed without double quotes because we have already changed the argument type to string. In this case, add the activities you want to perform. I am just using a log message activity.
Similarly, add another new case
Failed. You can add a new case for Error as well. But I will be using the default for it. Default is used when none of the cases is satisfied.
Here is how the final flow looks like.
Test the flow by running the process.
Output when message is passed
Output when message is some error occurred
Thank you All!!! Hope you find this useful.
If you liked our content and it was helpful, you can buy us a coffee or a pizza. Thank you so much.
You must be logged in to post a comment.