What this scenario does: Retrieves Shopify orders, verifies if the orders are part of a specific category and adds the details to a Google Sheet.
Level Of Difficulty: Advanced
Implementation Time: 20 minutes
You have probably already read the tutorial on How to Use Basic Functions to Manipulate Data in Your Scenarios so in this one, let’s dig a little deeper into some of the more advanced functions that are commonly used in scenarios.
In this use case, a new range of superhero toys are sold in a Shopify store and I want to track the sales of these items only. By doing so, data on which superhero is the most popular is provided and will assist with the marketing strategy.
This scenario can be recreated so let me show you how to set it up.
Configuring the scenario
The scenario consists of the following modules:
- Shopify > Watch orders
- Tools > Set variable
- Google Sheets > Add a row
In the Shopify > Watch orders module, add or select an existing connection.
Next, select the Status, Financial status and the Fulfillment status. To keep things simple for this demo, let’s leave all set to any and set the limit to 3 to retrieve 3 orders during an execution:
When a product is purchased, the title of the product is compared to a list of superhero names to see if it matches any of them. If it does, it will be added to a Google Sheet.
But, the titles usually contain more than just the Superhero’s name, for example, Spiderman elite series. Therefore each word in the title needs to be separated first in order for the scenario to work correctly.
To do this, add the Tools > Set Variable module to create a Variable which will be an array containing a collection of the separated names. Give the Variable a name and in the Variable value field, select the split function found under the Text and Binary tab:
Then, map the Line items: Title element outputted by the Shopify module in the brackets and the keyword Space after the semi colon:
Next, add the second Set variable module, create a Variable which will be an array containing the list of Superhero names that the title of the product will be compared to. You’ll need to add the names to an empty array.
This time select the Add function found under the Functions for working with Arrays tab and map the emptyarray keyword in the brackets. Then, simply enter the required names after the semicolon:
Now add the Iterator which is required to iterate through the array containing all the separated words in the product’s title. Simply map the element outputted by the first Set Variable module:
On the route between the Iterator and the Google Sheets module is a filter. This filter is important here since it verifies if the title contains any of the names in the array created in the previous module.
To set up the filter, map the array element outputted by the second Set Variable module. Since you are working with an array, select the contains (case insensitive) Array Operator from the list. Lastly, map the Value element outputted by the Iterator to the bottom field:
The final module in the scenario is the Google Sheets > Add a row module.
Add or select an existing connection then select the Spreadsheet and the Sheet that you want to add the Data to. Ensure that you have the relevant headings in the sheet:
Now map the Value element outputted by the Iterator to the Name field and the created at element from the Shopify module to the Date field:
You could also add the full product name to the sheet if you want to track the specific items sold. In this use case only the Superhero name is required so let’s leave it as is.
Alright all set!
Now lets go over to Shopify and create 3 orders. Let’s use a Hulk limited edition as the first order, a Mercedes Benz toy car as the second and a Spiderman elite series as the third:
Now click on Run once to execute the scenario.
The execution all 3 orders were retrieved. Each word in the product’s title of the orders were then split in the first Set Variable module:
The Superhero names were added to the empty array:
The variable containing the separated title words was then iterated:
The filter verified if the variable containing the Superhero names contained any of the values:
Here you see that 2 out of the 3 orders met the filter’s criteria and was added to the Google Sheet:
And there you go! That covers the more advanced types of functions that you can use in your scenarios.