Question

Create a new record in Airtable based on product quantity

  • 23 March 2022
  • 2 replies
  • 42 views

Hi

 

I would like to create a record in Airtable for each single item my customers order on my Shopify website.

But I don’t know how to create a loop based on the quantity that appears in the line items.

As an example, let’s say my customer has ordered 2 of the same t-shirt, I wold like to create 2 records in Airtable with quantity = 1 for each.

 

Thanks a lot for your help!


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

2 replies

Userlevel 7
Badge +14

Hi @Greg DV 

Good question.

Try using the Looping app: https://zapier.com/apps/looping/help

 

Hi 

 

Thanks for your quick reply!

I was able to loop only on the number of items in the array but not on their actual value.

For example if I have the following a line items for 2 products being

[Product 1, Product 2]

[Quantity = 1, Quantity = 2]

I am able to loop twice (as I have 2 products) but I didn’t figure out how to loop 3 times as I would like the result to be:

[Product 1, Quantity = 1] 

[Product 2, Quantity = 1] 

[Product 2, Quantity = 1] 

 

But I think I figured sth out with the following Zap

 

The code to create single product orders being 

 

const URL = inputData.File_URL.split(","); 
const filtered_URL = URL.filter(url => url.includes('pdf'));
const Quantity = inputData.File_Quantity.split(",") ;
const Id = inputData.Product_Id.split(",");
const final_URL = [];
const Product_Id = [];

let k = 0
for (let i = 0; i < Quantity.length; i++) {
for (let j = 0; j < Quantity[i]; j++) {
final_URL[k] = filtered_URL[i];
Product_Id[k] = Id[i];
k = k+1;
}
}

output = [{final_URL,Product_Id}];