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 1
Badge

RicoSystems,

What I got   (the difference in they input data was that only the Quantity has commas without data in between.0

 

Userlevel 3
Badge +1

Chris,

One of the little quirks of Zapier and object and arrays is that in some cases you lose the ability to parse things correctly if they are not communicated as JSON strings. Nulls and string values with internal commas can be particularly difficult.

To that end, I think you’ll have better luck if you use the code I sent you most recently, applying the JSON.stringify fix to create an array of JSON strings. That will still trigger the fork, but each fork will get a single JSON string which can be parsed into the line item object you need. If you go back up to your original inputs - the three or four arrays that you concatenate, then you’ll be on track. If that fork is driven by an array of JSON strings, then the subsequent fork structure can operate the same way, with a filter step to separate the first fork from the subsequent fork(s).

Bear in mind the overall limitations that Tim mentioned.

If you’d find it helpful to continue this either via email or chat, just Google me - I’m easy to find.

Joey (aka RisoSystems)

Userlevel 3
Badge +1

Chris,

PS: Remember that a string is treated like an array - you have to parse the thing back to an array of objects before an index will work the way you need.

ie:

If StringValue = ‘ “none”, “something”, “something else”, “something, or maybe nothing” ‘ then StringValue[14] == “h”

If StringArrayValue = [“none”, “something”, “something else”, “something, or maybe nothing”] then StringArrayValue[2] == “something else”

 

 

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.

Hello! Is there any update on this particular limitation? We’re running into the same problem.

My action is a webhook GET that returns an array of data that I cannot filter from this particular service (Paychex) due to an API limitation, so it is returning over 250 results in the JSON. It does, however, allow for pagination, but I’m not sure how to tackle that using Zapier.

Any ideas of a workaround to get the Javascript code to either work for >250 items OR alternatively, limit the number of responses using API pagination?

Any help is greatly appreciated!

Userlevel 3
Badge +1

Tim, if the array that kicks off the loop were parsed in such a way that groups of array items would Branch off to other zaps would the same limitation still apply? for example, could the first 100 values of the array the bundled up and sent to one's app while another hundred gets sent in a separate batch? Exactly how does the limitation apply?

Userlevel 1

Just wanted to chime in and say this saved my day (and a ton of my time in the future)!  Thanks for sharing!

Userlevel 1

Hey Tim, 

Thanks for this solution! I tried the code out and wanted to ask if there’s a way for the first line “Deal” to repeat? So that “Order 1” would be repeated for each “Product”? 

Right now, the zap doesn’t repeat the first line “deal”: 

 

Ideally, it would look like this: 

 

Any help is greatly appreciated! Thank you!

Userlevel 1
Badge

@TimS is it possible to nest multiple loops? i.e. code step>using line items in step>another code step>using those line items?

Userlevel 1

@TimS You are an absolute godsend.

 

Not only have you been able to the solution to solve a very specific problem but you have provided it in a way that can be reused to solve any number of other problems using only the Zapier inputs!

 

Seriously man, great work, the world needs more people capable of providing solutions like this one, if you are ever in New Zealand I owe you a drink of your choosing.

Userlevel 1

@TimS - Can you please help me out with using this code?  I’m trying to understand how to deal with blank values coming in to this step from a CSV.

 

Background:  I’m running a daily download from a wordpress website.  I then need to parse the data and pass it to a ticket in Hubspot.

 

It appears that the data is being read correctly from the CSV. 

 

The input data where I am getting blanks is the field RFP Toolkit. You can see that there are blanks in the CSV file.

 

I have not altered your original code.

 

The output log shows the 1 value being assigned to record 1, not to record 3.  And records 2, 3, 4 are blank.

 

I have also looked at your post about assigning default values to Code steps, but that resulted in the same output, with the 1 being assigned to the first record.

 

Any insight you could offer would be incredibly helpful.

 

Scott

Userlevel 7
Badge +3

@TimS is it possible to nest multiple loops? i.e. code step>using line items in step>another code step>using those line items?

Hey @David@Zapwise ! 
It is technically possible but not advisable. We discovered while working on the Looping by Zapier app that nested looped actions often get stuck in a playing state, so we prevent Zaps from turning on with multiple Looping Steps. That being said, we’re working on improving the way the underlying tech works for Looping so that in the future nested Looping will work.

Userlevel 7
Badge +3

I’m trying to understand how to deal with blank values coming in to this step from a CSV.


Hey @scottfmosley !

The reason that you’re getting those inconsistent results with the blank fields is that the Code by Zapier Step doesn’t have native line item fields. That means that each element of the line items from the CSV are converted into comma separated strings, and null (empty) values are dropped.

When we try to line up the different elements where some have had entries dropped, they get misaligned like that.

This is part of the reason that we created the Looping by Zapier Beta app. It has a “Create Loop from Line Items” Action that does essentially the same thing as the code here, but with proper Line Item fields so that data isn’t misaligned when there are null values, and we made the interface a bit nicer, too!

I’d definitely recommend trying the Looping by Zapier Action instead of the Code Step first.

If you find you wanted to do something custom in the code, you can read more about how to get line items into Code Steps intact in a more recent post I wrote here: 

It’s a long post, but it’s mostly screenshots because this is a tricky thing to get right!

Userlevel 1

@TimS - Worked like a charm!  Thanks very much.

Hi - everyone on this thread is amazing and everything you’ve shown is SO CLOSE to helping me solve my problem. But not quite yet.

 

This is start-to-finish the outline of my Zap so far. I have users submit forms with multiple image attachments. I need each of those images to create its own line in an AirTable database.

 

 

 

Here is the end result. The top line is what is happening; the next 4 are what I want to happen (I am fixing these manually right now.)

 



Here’s my JavaScript section:

 

This is the output I get

 

 

 

And this is what I’m doing in the AirTable section (‘Preview’ is the name of the field in AirTable where the photo attachments are stored/viewed.)