Do you often find yourself repeating the same actions across different zaps in Zapier? Well, then the Sub-Zap by Zapier action was made just for you! You can take all those grouped actions that you use repeatedly across your zaps and put them in a single sub-zap that you can then request from any other zap in Zapier.
For anyone with programming experience a sub-zap functions similar to a function in programming where you pass input parameters to the function from your main program, the function does some work with these parameters, and then returns output values that you can use in your main program.
This feature will save you oodles of time. On top of the time saved from not having to put the same actions into zaps, again and again, you will also save time when maintaining and updating the actions in the sub-zap. Previously, if there was an update needed to a group of actions used across multiple zaps then you would have to make the update multiple times. Now you can make the update in one single place, the sub-zap!
Now that you know a little about sub-zaps and how they can save you from repetitive strain injury let’s take a look at how to use a sub-zap within Zapier. We’ll use the example of tagging sales members if their names appear on a lead notification in Slack.
Start a Sub-Zap Trigger Event
Once you choose the “Sub-Zap by Zapier” app and the “Start a Sub-Zap” trigger event, you will need at list one input parameter for this sub-zap to be functional. Under the “Input/Argument List” we are going to include an input parameter called
text and make this a required input by putting the “(Required)” keyword after the input name.
text input variable is the message from Slack, which will be passed from the requesting Zap outlined below. This sub-zap will parse this message in order to determine if there are any sales member names present and if so prepare a message that will tag these sales members in the thread of the original message (as shown in the images in the introduction of this post).
Get First Names and Slack Tag Names
The Slack Tag Names Google sheet stores a list of all sales members along with their tag name, which is used to mention them on Slack, in the “Front End” tab. Since Zapier’s Google Sheets integration can only read in a maximum of 20 rows at once some finagling must be done in order to get all these names into Zapier in one action.
This is where the “Back End” sheet comes into play. The join formula below is used in both the “First Name” and “Slack Tag” columns to join every row value from the corresponding columns in the “Front End” tab with the asterisk character.
=JOIN("*", 'Front End'!C2:C)
Then in Zapier the “Lookup Spreadsheet Row” is used to search the “Lookup” column for the
***lookup*** value from the “Back End” tab. Since this lookup value will never change this action will always bring in the “First Name” and “Slack Tag” strings.
Parse Owners and Prepare Slack Message
Once the “First Name” and “Slack Tag” strings have been imported into Zapier the Python code in Step 3 splits these strings using the asterisk as a delimiter so that parallel lists are created where the Slack tag at index i in the
t_names list corresponds to the first name at index i in the
f_names list. The
mapping dictionary is then created from these 2 lists so that using a first name as a key in the mapping dictionary i.e.
mapping[first_name], will return the Slack tag for that first name.
The input Slack message is then searched using Regex patterns to extract the
Lead Owner, and
Lead SDR names, which are then stored in the
l_names list. A for loop is then used to iterate through the
l_names list and add the owner or SDR name to a string if the name is populated and is not present in the string already. The owner or SDR name is prepended with an “@” character so that when this string is sent to Slack the salesperson will be tagged.
Return From a Sub-Zap
Once again the “Sub-Zap by Zapier” app is used but this time the “Return From a Sub-Zap” event is selected. In the “Set up action” section, the new message created in Step 3 containing the sales member tag names is put into the “Output/Return Values” field so that this new message will be returned to the requesting Zap outlined below.
Requesting Zap Setup
New Message #inbound-formfills Channel
Select the “New Message Posted to Channel” trigger event under the Slack app and then once you have chosen the channel you would like to monitor e.g. #inbound-formfills, ensure that “Trigger for Bot Messages” is set to “Yes” so that sales notifications from a marketing automation tool such as Marketo will trigger the zap.
Marketo Bot Filter
In this case we are only interested in Slack messages sent from Marketo. Therefore, a filter is used in Step 2 to check that the ‘User Name” obtained from Step 1 does not exist, since only human Slack members will have a “User Name”.
Call a Sub-Zap
The “Call a Sub-Zap” action is used from the “Sub-Zap by Zapier” app to request the sub-zap we created above. In the “Set up action” section you can see that the required
text field we specified as an input argument in the sub-zap setup now appears under the “Input Argument” section and is ready to be populated with the incoming Slack message from Step 1.
At this point, the sub-zap will take the input Slack message, run through its steps, then return the message containing the salespeople who will be tagged in the thread of the original Slack message.
Empty Message Filter
Step 4. then takes the message returned from the sub-zap and ensures that the message does not equal “NA” since this is the value used to initialize the message variable and if it has not changed then that means there are no salespeople to tag.
Tag Owner(s) in Thread of Original Message
Finally, the “Send Channel Message” action is used from the Slack app to post the salesperson tagging message returned from the sub-zap in the thread of the original incoming message. After selecting the channel and populating the “Message Text” field with the message returned from the sub-zap in Step 3, make sure to populate the “Thread” field with the “Ts” parameter of the incoming message from Step 1.
Sub-Zap Things to Note
Do NOT Use Filters in Sub-Zaps
One thing to be cautious with when it comes to sub-zaps is the use of filters. For example, for the sub-zap we created above you might have wondered why don’t we take the “Empty Message Filter” step and “Tag Owner(s) in Thread of Original Message” step from the requesting zap and put these in the sub-zap too.
This would definitely have been useful because if you want to have different requesting zaps listening to different Slack channels they would all use these 2 last steps. So it would make sense to pass the channel id as an input argument to the sub-zap and move these 2 steps into the sub-zap so they can be re-used.
However, take the scenario where the message returned from the “Parse Owners and Prepare Slack Message” is empty. If the “Empty Message Filter” step were moved to the sub-zap then the sub-zap would stop at this filter and it would never reach the “Return From a Sub-Zap” step, meaning that the sub-zap and then the requesting zap will never complete.
I have not tested what will happen in this scenario but I am guessing the sub-zap would time out causing all subsequent steps in the requesting zap that depend on the sub-zap action to fail.
Best not to run into this!
If you are interested in setting up sales tagging like this in your Slack instance but have not set up sales notifications from Marketo then stay tuned for my upcoming post on how to use webhooks from Marketo to create messages in Slack.
In the meantime, if you are curious about merging leads in Zapier, optimizing zaps, or integrating with the Dropbox, Airtable, and Rebrandly APIs then take a look at the Zapier section on my site, and while you’re there see what else takes your fancy!