Zapier loop for each record in view


#1

So, I am trying to write a snippet to use in the code step of Zapier.

Their documentation says

[output] An object or array of objects that will be the “return value” of this code. You can explicitly return early if you like.

Setting the output to an array of objects will run the subsequent steps multiple times — once for each object in the array. If Code by Zapier is the Zap’s trigger and an empty array is returned, nothing happens.

My problem is that this sure looks like an array of objects to me, but Zapier says its not. Any ideas?


#2

Hi @Philip_Bassham

I’m not really a programmer - but I’ve used the Javascript code step to loop through records on many occasions - here is an example:

This brings a comma separated list of record ids from a Link field and converts it into an array of objects - and later steps run for each.

You need to be aware that there is a limit on this ability in Zapier - it will only loop through up to 25 objects. There is a way around this - which is to first split the initial comma separated list into an array of objects each themselves contain a comma separated list of 25 items - and so on.


#3

I actually use that snippet that you wrote, so I am glad you replied.

I am not a programmer either, I just can’t figure out how my output is different from what your output is and not what Zapier wants.


#4

Hi

Here is the equivalent output from one of my code steps:

[ { thisReminderObj: { record: [String: ‘recSRKjZTgpQoemE8’] } }, { thisReminderObj: { record: [String: ‘recX3M4SxiEzdCzXY’] } } ]

You’ll see it’s different from yours - the object is called thisReminderObj with a property called record and the object is repeated (an array of objects??). I think yours is simply an array??

Here is the loop that builds it:

do {
var thisReminder = new String(reminderListArray[i]);
var thisReminderObj = {};
thisReminderObj.record = thisReminder;
output.push({thisReminderObj});
i++;
}
while (i < reminderNos);


#5

Thanks. I finally got it.

This loops through all the records from a view or search and performs the following steps for each record.


#7

I am basically using code by zapier to loop through my employee database and to send automated birthday email to them. I have used Code by Zapier to loop through the database to find multiple records. I am using schedule by zapier to trigger every hour and capture today’s date and search through the database and send them the email. But, unfortunately, zapier is able to find only one record, even after using the code posted by philip. I am posting the snaps. Could you both please see where am I faulting?


#8

i bet you’re just looking at the results from the test. that just shows the first result found. Once you run it in production, it will process the rest of your actions for each and every response returned.


#9

Hey @openside, Ya I figured that out. Thanks for the reply. But still, my this code is not returning all the results. It is just mailing one particular person multiple times.


#10

Try using Integromat instead - it can read an Airtable table using a formula and return multiple records and then following steps will perform for each.

The only slight pain (with Airtable specifically) is that it sometimes times out in the design process meaning you have to wait a few minutes before continuing - this doesn’t effect the live process though. Airtable / Integromat really need to sort this out because Integromat has far superior logic capabilities to Zapier (conditional branches, loops etc).


#11

What’s your first step? Airtable “New Record in View”?

I am trying to set up this kind of loop where, once weekly, all new Airtable records in a particular view are sent via gmail. I figured out the Zapier Schedule trigger, but I’m lost when it comes to Code by Zapier’s Input Data. What Airtable trigger is your “Checklist Items” coming from?


#12

I have set most of my triggers as Slack messages, which I can trigger manually by sending a message to that channel, or set up from an Airtable notification on the event of an updated record in a particular view, for instance.

As far as the input data, in my code at least, it comes from the API fetch which brings in all data straight from a particular Airtable view.

So, the trigger can be anything, it doesn’t have to contain your trigger step. The input data is parsed from the API fetch call in your code.

For example, I have a “send messages with ManyChat” zap.

  1. In Airtable, I have 1 field that contains the message to send, and another checkbox field as a ‘send’ button.
  2. So, I have a Airtable view that is based on that ‘send button’ checkbox.
  3. And when that view is updated (I check a box), an “Airtable view updated” notification gets sent to a slack channel.
  4. My trigger for Zapier is a new message in that channel. And my code step gets all records in that view, sends the message via ManyChat, and uncheckes the “send” box, resetting the view.

Maybe that will help a little?


#13

Nishant - we (Openside) just released an ehanced zapier connector that can handle bulk items so can read in multiple rows at once to further process. This can likely help you do what you need.