Skip to main content

Is it possible to flatten line items within a Zap?


Ultimately there isn't a great way to deal with this, but if you're up for it, this can be achieved in 1 step using a few lines of code.

Let's say I have this set of Line Items here: 

line items for Sam _ Zapier Google Chrome, Today at 7.27.12 pm.pngTo convert those into single usable fields, you'll first want to set up your Input Data. On the left you'll want to represent what each group of line items fields are: 

line items for Sam _ Zapier Google Chrome, Today at 7.36.01 pm.pngNext, using some code we can create title for the new fields, generating a new array: 

SnappyApp SnappyApp, Today at 7.29.00 pm.pngThe text version of that code is:

output = {}

const names = inputData.name.split(',') // giving a title to the new fields

names.forEach(name => outputpname] = {})

// each line here iterates over each field, splitting it by the comma and adding it to the output array.

inputData.name.split(',').forEach((name, i) => {outputpnamesmi]].name = name})

inputData.price.split(',').forEach((price, i) => {outputpnamesmi]].price = price})

inputData.qty.split(',').forEach((qty, i ) => {outputpnamesmi]].qty = qty})

output = output];

You can experiment with this to get slightly different outcomes, or you can literally copy and paste that code into any code step and it'll iterate over those arrays. Using the above example, when the code is tested the output is: 

line items for Sam _ Zapier Google Chrome, Today at 7.31.37 pm.pngWhich appears in the following steps like so: 

line items for Sam _ Zapier Google Chrome, Today at 7.31.58 pm.pngHope that helps!