Skip to main content
Best answer

Creating a Foreach Loop in Code by Zapier to create objects from a CSV file


Ibanez1998

Hi,  I am importing a CSV I get from an email and parsing that CSV, but when I go to add the data as contact records in the Mojo app (a CMS system which by the way doesn’t appear to support line items) I get funky results and errors like State: FL, FL, FL, FL (Failed to add record, state abbreviations must be 2 letters only, yours has 12).  So…  I would like to use Code by Zapier to create a ForEach Loop to overcome this issue.  I want the CSV file to be read but only sent 1 line at a time.  I’m struggling with a way to do this.  Does anyone have any suggestions?  I can write to Google Sheets if absolutely necessary, but I’d rather just do this in code and remove additional dependencies.  I have enough dependencies already.

Best answer by TimSBest answer by TimS

Hi @Ibanez1998 !

I spotted your question, and just in case you’re still looking for a way to do this with code, I recently wrote up an article about this in the community here: 

One limitation to be aware of is the maximum number of iterations a Code Step can run through is 250. Are your CSVs less than 250 rows of data?

Please take a look and let me know if you have any questions!

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

steph.n
Forum|alt.badge.img+8
  • Builder
  • 899 replies
  • August 24, 2020

Hi there @Ibanez1998 - Thanks for the question. It sounds like you were on the right track, especially if you want line item support. Our go to is usually Google Sheets but also, have you checked out Formatter by Zapier, specifically the Utilities function that has line item support? Let us know if you have further questions or still need additional support.


TimS
Forum|alt.badge.img+3
  • Zapier Staff
  • 21 replies
  • Answer
  • September 1, 2020

Hi @Ibanez1998 !

I spotted your question, and just in case you’re still looking for a way to do this with code, I recently wrote up an article about this in the community here: 

One limitation to be aware of is the maximum number of iterations a Code Step can run through is 250. Are your CSVs less than 250 rows of data?

Please take a look and let me know if you have any questions!


Ibanez1998
  • Author
  • Beginner
  • 1 reply
  • September 4, 2020
TimS wrote:

Hi @Ibanez1998 !

I spotted your question, and just in case you’re still looking for a way to do this with code, I recently wrote up an article about this in the community here: 

https://community.zapier.com/tips-and-inspiration-5/how-to-repeat-action-s-in-your-zap-for-a-variable-number-of-values-3037

One limitation to be aware of is the maximum number of iterations a Code Step can run through is 250. Are your CSVs less than 250 rows of data?

Please take a look and let me know if you have any questions!

Thanks Tim.  At this point I forgot what I was trying to do.  I either did what I needed with a spreadsheet, or I just gave up.