Best answer

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

  • 28 July 2020
  • 3 replies
  • 862 views

Userlevel 1

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.

icon

Best answer by TimS 1 September 2020, 19:44

View original

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

Userlevel 7
Badge +8

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.

Userlevel 7
Badge +3

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!

Userlevel 1

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!

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.