How to repeat action(s) in your Zap for a variable number of values

How to repeat action(s) in your Zap for a variable number of values

Show first post
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

39 replies

Userlevel 3
Badge +1

Chrisboat - While I’ve not tried it myself, it seems to me that you could add a filter step at the bottom of the first “fork” which would only continue if the index+1 = the size of the first set of values. The following step could retrieve the next array and process just as the last fork had done.

Again, I haven’t tried it, but it seems like a logical extension of the indexed array approach.

Userlevel 1
Badge

Your code worked perfectly. I added a code step to split my arrays. I use this to add multiple occurrences of the same record in Airtable.

 

 

My understanding of your fork step is that all of the steps after the fork will run as many times as the fork triggers. I would like to add a second independant fork step that would run after this fork completes to add another set of different records based on another set of data. Is this possible?

Userlevel 3
Badge +1

Here’s a little hack that serves me well in these situations:

When the various array items that generate the fork or loop have associated values - in one of my cases each is associated with a line item which has an image and a list of options.

Before hitting the fork I create a set of arrays (I could do this with an array of objects, too, but arrays are easier).

Before hitting the fork in the road I zero out a value in Storage.

As each loop is executed, I first retrieve the value and use it as an index to the earlier arrays.

Before ending the loop, I increment the value.

This is a tedious way of saying I use a storage variable as the index of a loop.

Hi @TimS ,

Your code works wonderful to run a loop. I want to create a loop inside loop. as you can see in SS. I want to run first loop against the total line items and the second loop against the quantity.

Can you please help. 

 

Thanks and Stay Safe,

 

Shahzad

Userlevel 1
Badge

This functionality is exactly what I needed. Typed in csv data fields and it created multiple records in Airtable.

I have input from Jotform that looks like this.

Configurable list

[{"Product":"8 \"","Quantity":"2","Flavour":"B Choc"},{"Product":"10\"","Quantity":"1","Flavour":"Lemon"},{"Product":"10\"","Quantity":"1","Flavour":"Vanilla"},{"Product":"12\"","Quantity":"2","Flavour":"Carrot"}]

Is there a way that your code could be adjusted to use this format or would it have to be extracted somehow and put into one of your 2 formats. Maybe some kind of Run Python in Code by Zapier. 

Python looks a bit complex to learn. 

Userlevel 2

OMG OMG! I was banging my head over the last few days to achieve this functionality. You made my day @TimS  😘🤯😍🔥

Userlevel 7
Badge +3

Hi @jonah and @ForYourIT,

Thanks for the questions and answers here! @ForYourIT is correct that we need to keep those limitations in mind, though in this case the answer is likely something else. 

I consulted with our Support Escalations team and I learned that the maximum number of times we can loop/fork in a Zap is 250. With 732 values to loop through, we exceed that limit and the Zap won’t work. 

I don’t believe that number can be changed, but I’m looking into learning more about this, and if there is a good workaround/solution, I’ll post another reply.

Userlevel 7
Badge +7

Hi @jonah I think I can answer your question.

The code by Zapier action has got some limitations. This is probably required so the system doesn’t get overused calculated by the usage, costs and amount of users. These are the following limitations:

  • The environment in which your Code steps run (AWS Lambda) has an I/O limit of 6MB. The total size of the code and the data processed by the Code cannot exceed that. If you're hitting this error, try to limit the amount of data your return from your function. For instance, don't return an entire JSON structure, just the keys you need.
  • Free users are limited to 1 second and 128mb of RAM. Paid users get well over double that at 10 seconds and 256mb of RAM. Your Zap will hit an error if you exceed these limits.

If you like, you can read more about this here. A solution within this limitations is already there however! If I you were one of my clients I would advice you to use AWS lambda yourself to run your code. I use it for some of my clients as well, and the great thing is you can activate it threw Zapier as well.

It does require some setting up of the environment, but it will allow you to run a bigger amount of data. Hope this helps you!

 

~ Bjorn

 

Userlevel 1

Hi Tim,

 

Is there a limit to the number of records / repeatable flows that can be played through the code?

 

This worked great when I tried it with zaps using a small number of records. Then I tried to set one up with a higher number of records (732 comma-separated values) and the zap seemed to get stuck and not play past the code.

 

Any thoughts?

 

Jonah

Userlevel 1

Wow, this will work for sure! I will do it and report back on results, thanks so much...

Userlevel 7
Badge +3

Hi Andreas, nice work getting this all set up!

You’re right that the code works best when there are no commas in your values, but in your case, there is a way you can work around this by using a Formatter Step for each Input Data Value before the loop starts.

Currently, you have Line Items mapped into your Input Data fields, and what happens is the Code Step converts those into comma delimited text and then sends them into the Code. If we use a Formatter Utilities Action with the “Line Item to text” transform, then we can choose our own delimiter. 

Instead of outputting the text with commas in-between, I like to use three pipes: |||

Then, in the Code Step if you change the Input Data values to your 3-pipe delimited text from the Formatters, you can change the code you highlighted to split on the pipes instead of single commas and that will protect your actual value containing a comma.

That line would change to: let li = inputData[key].split(“|||”);

And that should do the trick!

Userlevel 1

Hi Tim, it now works perfectly for me! And I am able to format and filter the forked results, so that my spreadsheet looks perfect.

 

I do have one question though, which may not have a satisfactory answer 🤞 

For one of my values, there is a comma within the text. This means that the code steps splits the text in half when it tries to split it at the end of the value.

Is there any way to avoid this from happening or does the code work best when there are no commas within the value itself?

 

Userlevel 7
Badge +3

Hi Andreas!

You’re welcome, and I’m glad to see you giving this a try :)

I took a look at your screenshots, and I can’t quite tell why things are not lining up. If we’ve created the line items with Line Itemizer, even if you have null values, the resulting rows in the Google sheet should line up, with some blank cells where the null values were. At least the subject and status rows should be lining up because there don’t appear to be any nulls there.

I see one “Subject” value in your line items “RE: Re: Note from...” that I don’t see in the spreadsheet screenshot, so I’m not sure what is happening there.

One suggestion I have here is if your date needs to be repeated for all the rows, for example, is to map in the single Date value in the Create Multiple Row(s) Step instead of the Line Item version. When you combine single values and line item values, the single values will be repeated once for each line.

For the other parts, it may be easier to troubleshoot if we could see the Zap setups. Because you’re not working on any Code Steps here, I’d recommend writing in to Support (https://zapier.com/app/get-help) if you still have questions about this one. If you could post the general answer here afterwards, that would be fantastic!

Best, Tim

Userlevel 1

Hi Tim, 

Amazing work, thanks so much! This opens up lot’s of possibilities.

I am trying my luck with the first option before cutting my teeth with the second.

It all seems to work perfectly, except that my line items contain some null values.

 

 

This results in uneven pasting onto the Google Sheet.

 

The Date and Status fields are not aligned with the message field…

What would you do in that case?🙏

Thanks!

Andreas