What this scenario does: Retrieves data from a Google Sheet, compares the input to a predefined text in the Switch module and adds the corresponding output to the sheet.
Level Of Difficulty: Intermediate
Implementation Time: Approximately 25 mins
Prerequisites: A Google account for Google Sheets.
In this tutorial, you will learn about the Switch module on Integromat but first, here’s a definition:
The Switch module is an in-built tool on Integromat that checks the input value for a match with the provided list of values and returns the output based on the result.
So you’re probably thinking what’s the difference between the switch function found under the general functions tab and switch module.
Well the switch function and the Switch module are similar however the Switch module also has the option to use a regular expression for matching values adding more capabilities to the Switch module.
Regular Expressions can be quite complex to apply, depending on the data you want to extract from your input text, so we recommend that you check out our full course on regular expressions for more complex examples and use-cases.
With that being said, the examples you will see in this lesson will be quite simple and easy to understand, but can also be useful in many scenarios.
In the first example, let’s match the input to a simple text in the Switch module. Responses from a Google form are added to this Google sheet here:
The responses are single words which are retrieved from the sheet and if it matches any of the values listed in the Switch module, it outputs the corresponding text which is then added to this column on the sheet:
Configuring the scenario
The scenario consists of the following modules:
- Google Sheets > Watch row
- Tools > Switch
- Google Sheets > Update a row
The Google Sheets > Watch rows module has a straight forward configuration so let me show you how to set up the Switch module.
In the Input field, simply map the element that contains the text that you want to check for a match with the list of values below, which in this case, is the Responses element outputted by the Google sheets > Watch rows module:
You can add an item to the list by clicking the Add item option:
There are 2 items already created. You can see that if the input value matches the word Disagree, it outputs the words Negative Statement:
If it matches Agree, it outputs Positive Statement:
If the responses don’t match either of the words, it outputs Unidentified:
It’s important to note that since this input is not a regular expression pattern, the input must match the text exactly in order to output the value here.
In the Google Sheets > Update a row module, after selecting the spreadsheet and sheet, map the Row number to the row number field and the Output element from the Switch module to the relevant field:
So let’s execute the scenario.
Scenario execution 1
Here you see that all 3 responses were retrieved, 2 of the responses each matched a different case in the Switch module and returned the desired output. 1 response did not match any case and outputted the Else condition:
And on the sheet, you see the responses with the corresponding outputs were added correctly:
So let’s say the responses were sentences but you want to check if they contain certain values, like the words agree or disagree in this case.
Since you are checking for a specific word in a sentence, you will need to use a simple regular expression pattern in the Switch module since the previous pattern won’t work.
All you need to do is simply wrap the words agree and disagree in brackets. In Integromat Regular Expression Syntax, the occurrence of a string between brackets will be matched in the input text. Leave the text in the Output field the same:
Ensure that you tick this box:
Lets’ execute the scenario again.
Scenario execution 2
The scenario executed successfully and the correct output for each response was generated by the Switch module and entered on the sheet:
So this was just a simple demonstration to show you how the Switch module can be used to manipulate data in scenarios.
Here’s a quick recap on the Switch module:
- The Switch module is an in-built tool on Integromat that checks the input value for a match with the provided list of values and returns the output based on the result.
- The Switch module differs from the switch function as it also has the option of using a regular expression pattern to match values.
- By using regular expressions in the Switch module input you can search your input text and match words within a sentence.
Now you can use the Switch module in your scenarios!