How to set up Switch cases
The execution paths are defined using Cases. Each case specifies the condition(s) to be met along with the next action to be executed if the condition is met.
-
Cases are evaluated sequentially, starting from Case 1. As soon as a case succeeds, the next action associated with it is executed, while the rest of the cases are discarded.
-
You can optionally specify a Default Case, which is executed if none of the other cases succeed.
-
You can also assign same case number, for example, Case 2, for two different execution paths with different conditions. In such a scenario, both the cases will be evaluated simultaneously, but only the case with matched condition (if any) will be executed. If both the cases fail, the next case will be evaluated.
We will now understand how to set up Switch cases with the help of an example.
Let's say your organization has a support request form on its website where users can raise requests for different departments. You want to create a workflow that will execute each time a new support request is raised, will check the department (IT, Operations, Content) for which the request was raised, and will then send the details of the request to the specified department through a specific channel.
- Add and configure trigger. First, we will setup a trigger that will fire off each time a new request is submitted through the request form. Select the 'Formstack - New Submission' trigger and configure it. Next, add Switch action to canvas, followed by the Asana, Intercom, and Cisco Webex Teams. connectors.
- Configure Switch cases. Connect Switch with all the connectors on canvas.
-
You will notice that case numbers are assigned by default at the time of connecting Switch with connectors. You can change these case numbers as per your requirements. As per our example, we have to set the following conditions:
If the department is IT, create a new task in Adana.
If the department is Operations, create a new note in Intercom.
If the department is Content, post a new message on Cisco Webex Teams space.
We will now define these conditions:
Start off by clicking on the line connecting the Switch action and Asana connector icon and click the Settings icon. The Condition window will appear on screen. Here, you can see the Select Case drop-down menu from where you can add cases and the Condition block from where you can set specific conditions.
Select Case: Click on the drop down arrow to see the list of available cases and select the case you want to assign to this execution path. Cases are evaluated in sequential order.As we have connected three connectors with Switch, you will see Case 1, Case 2, Case 3, and the Default Case in the drop-down list.
Condition: Click on the Add Condition button and then click Add Filter. In the condition block that appears, specify the condition you want to set.
-
For this example, we will configure the condition block as below:
Input: Add the key name of which value you want to check, from the Trigger data. Here, we will add the Department key.
Condition: Select Exactly Matches condition from the drop-down list.
Expected: Enter the value you want to compare against the form value. Here, we will enter IT.
-
Once you have entered these details, click Done. This will take you back to canvas. Repeat this procedure for:
Case 2 (Switch and Intercom, where expected value in condition is Operations.
Case 3 (Switch and Cisco Webex Teams, where expected value in condition is Content.
-
Configure all actions using the added connectors We will now configure the actions to retrieve and send form data if the condition they are associated with is met. Configure Asana - Create Task, Intercom - New Note, and Cisco Webex Teams - Post new Message actions by selecting relevant accounts. In the Body (or other such relevant) field of each action add Trigger Data given on the left-side of the configuration window and click Next.
After this, test the configured action, and click Done. Now when any user submits the request form, the Formstack - New Submission trigger will fire off this workflow. The Switch action will then traverse through cases one-by-one to check for which department the request was raised and depending on that, will execute the relevant action, which will in turn send form data to the specified department.