Zapier Loop Action

With the amount of data being collected and the number of tasks to be completed for this data increasing, the ability to iterate and perform actions for each row in a dataset is vitally important for the marketing operations lead. This post will show you how to use a Zapier loop action to loop through and update rows of a Google sheet to give you a solid foundation that you can then build upon in your own Zaps.

Customer Database Example

For this post, we will use an example customer database in Google Sheets containing the “First Name”, “Order #”, “Email Address”, “Phone Number”, and “Delivery Date” of each customer. The “Delivery Today?” field is a checkbox field, which indicates whether the customer’s order will be delivered today.

We will use a Zapier loop action to compare today’s date to the “Delivery Date” value for every customer to set this “Delivery Today?” field to either be TRUE or FALSE. As shown in the second image below, we will use the “Schedule by Zapier” app to trigger this zap to run every day so that the “Delivery Today?” column is always up to date.

A Google sheet containing rows of customer information
Database of customer information
The "Schedule by Zapier" trigger being used to run the Zapier loop action every day
Trigger to run the Zapier loop action every day

Zapier Loop Action Workflow

An overview of the actions contained within the Zapier loop action
Zapier loop action overview

Zapier Loop Action Setup

The “Create loop from numbers” action event from the “Looping by Zapier” app is used to loop through each of the rows in the customer database. Since the first row of the Google Sheet is the header and we want to loop through every row, we will set the “Loop Iteration Counter Start” to 2 and the “Loop Iteration Counter Increment Amount” to 1.

With these 2 parameters set and taking into account Zapier’s 500 loop iterations restriction that means the maximum value we can set the “Loop Iteration Counter End” to is 501. If you have more than 500 rows of data that you need to update then you will need to use nested looping in Zapier (see the Zapier For Each Loop Quick-Start Guide).

Zapier loop action configuration
Zapier loop action configuration

Get Google Sheet Row

Once the Zap has been triggered, the first step is to obtain the “Delivery Date” value for the customer in a row. To do this the “Get Many Spreadsheet Rows” action from the Google Sheets app is used to pull in 1 row at a time from columns A to F. The “Loop Iteration” value from the Zapier loop action is used in the “First Row” field so that each row of the sheet will successively be accessed with each iteration of the loop.

If you want to see how to use the “Get Many Spreadsheet Rows” action to pull in multiple rows at once and how to transform the output to be used in subsequent actions then take a look at the How to use Zapier with Google Sheets post. Alternatively, take a peek at the Zapier Google Sheets Quick-Start Guide for more general guidance on the best option to import data from Google Sheets depending on the number of rows or the amount of data you want to import.

Setup of the Zapier "Get Many Spreadsheet Rows" action
Get row from Google Sheet

Python Code

Next, we will use a few lines of Python code to determine whether today’s date matches the “Delivery Date” for this customer. Since the “Delivery Date” column in the Google Sheet is in dd/mm/yyyy format, the “Date Month, “Date Day”, and “Date Year” output from the “Schedule by Zapier” trigger are joined together using the “/” character so that we can get today’s date in the same format.

The Python code then splits the string output from the “Get Many Spreadsheet Rows” action into an array using the “,” character as a delimiter and accesses the 5th column of this array to get the customer’s “Delivery Date” value (P.S. array indexing starts at 0 in Python which is why we use array[4] instead of array[5] below).

Then a conditional logic statement is used to set the delivered_today variable to TRUE or FALSE depending on whether today’s date equals the “Delivery Date” value for this customer.

array = input['row'].split(",")

if array[4] == input['today']:
    delivered_today = True 
else:
    delivered_today = False

return {'delivered_today':delivered_today}
Python code in the "Code by Zapier" action to check if the delivery date is today
Python code to check if delivery date is today

Update Google Sheet Row

The final step involves using the “Update Spreadsheet Row in Google Sheets” action to set the “Delivery Today?” field equal to the “Delivered Today” output from the Python code in Step 4. Notice again how the “Loop Iteration” output from the Zapier loop action is used to specify which row in the Google Sheet should be updated.

Part 1 of the setup for the "Update Spreadsheet Row" action in Zapier
Part 2 of the setup for the "Update Spreadsheet Row" action in Zapier
Update row from Google Sheet

Zapier Loop Action Follow-Ups?

Now that you have gotten a taste of looping in Zapier there might be a few more things that you are interested in doing now:

If you are enjoying this content and want to know when future posts launch then subscribe using that lustrous flamingo pink button at the top of the page!

Leave a Reply

Your email address will not be published. Required fields are marked *