Skip to main content

Hello,

I have a list of text items that I would like to loop through to create 2 outputs. One array that contains the unique items in the list, and another that contains the occurrences of those items.

 

I am trying to create an Invoice in Quickbooks and I want the invoice to have the item and the quantity, instead of a duplicate item over and over again with a quantity of 1.

 

Thanks in advance!

 

Kind regards,

Josh

 

 

 

Hi @Joshua Mursic! Would you please include a screenshot of a sample of the original array? Or confirm that I’m understanding it correctly with the example below?

var origList =  "item 1", "item 1", "item 1", "item 1", "item 1", "item 1", "item 1", "item 2", "item 2", "item 3", "item 3", "item 3", "item 3"];

Where the desired output would be:

itemList = item 1, item 2, item 3];

qtys = 7, 2, 4];


Hi @Joshua Mursic 

Good question.

Check out some of the related Code Mode topics that may provide guidance: https://community.zapier.com/search?q=Code+Mode&search_type=tag


Hi @Joshua Mursic! Would you please include a screenshot of a sample of the original array? Or confirm that I’m understanding it correctly with the example below?

var origList =  "item 1", "item 1", "item 1", "item 1", "item 1", "item 1", "item 1", "item 2", "item 2", "item 3", "item 3", "item 3", "item 3"];

Where the desired output would be:

itemList = item 1, item 2, item 3];

qtys = 7, 2, 4];

Hey Todd!

Thanks for the help!

Yes this is exactly correct.


@Joshua Mursic Awesome! This should do it for you :)

const arr =  "item 1", "item 1", "item 1", "item 1", "item 1", "item 1", "item 1", "item 2", "item 2", "item 3", "item 3", "item 3", "item 3"]; // Obviously, replace this with the actual array from your inputData

const items = ];
const qtys = ];

for (var i = 0; i < arr.length; i++) {
if (items.includes(arrri])) {
qtyssitems.indexOf(arrri])] += 1;
} else {
items.push(arrri]);
qtys.push(1);
}
}

output = {items, qtys}];

And this is what the result looks like when placing it into a QBO create invoice step:

 


@Joshua Mursic Awesome! This should do it for you :)

const arr =  "item 1", "item 1", "item 1", "item 1", "item 1", "item 1", "item 1", "item 2", "item 2", "item 3", "item 3", "item 3", "item 3"]; // Obviously, replace this with the actual array from your inputData

const items = ];
const qtys = ];

for (var i = 0; i < arr.length; i++) {
if (items.includes(arrri])) {
qtyssitems.indexOf(arrri])] += 1;
} else {
items.push(arrri]);
qtys.push(1);
}
}

output = {items, qtys}];

And this is what the result looks like when placing it into a QBO create invoice step:

 

Amazing! Thanks so much!