Question

How to loop through an array of objects with nested objects.

  • 15 April 2024
  • 1 reply
  • 17 views

I run javascript code to create line items of invoices, where each invoice can contain multiple line items.  

I can successfully use a Loop Action to loop through the invoices but the line items for each invoice seems to show every line item across all invoices.  How can I loop trough each line item with its corresponding line items so that I can create invoices in QBO.

Here is the output of the javascript code:
{
  "myLineItems": [
    {
      "CustomerName": "Test for Invoicing",
      "InvoiceDate": "2024-04-14",
      "Terms": "Net 30",
      "LineItems": [
        {
          "Description": "105587",
          "Amount": 200,
          "DetailType": "SalesItemLineDetail",
          "SalesItemLineDetail": {
            "ItemRef": {
              "value": "1"
            },
            "Quantity": 20,
            "UnitPrice": 10,
            "TaxCodeRef": {
              "value": "NON"
            }
          }
        },
        {
          "Description": "105587",
          "Amount": 195,
          "DetailType": "SalesItemLineDetail",
          "SalesItemLineDetail": {
            "ItemRef": {
              "value": "1"
            },
            "Quantity": 19.5,
            "UnitPrice": 10,
            "TaxCodeRef": {
              "value": "NON"
            }
          }
        }
      ]
    },
    {
      "CustomerName": "Test 2 for Invoicing",
      "InvoiceDate": "2024-04-14",
      "Terms": "Net 30",
      "LineItems": [
        {
          "Description": "105593",
          "Amount": 83.7,
          "DetailType": "SalesItemLineDetail",
          "SalesItemLineDetail": {
            "ItemRef": {
              "value": "1"
            },
            "Quantity": 18.6,
            "UnitPrice": 4.5,
            "TaxCodeRef": {
              "value": "NON"
            }
          }
        }
      ]
    }
  ]
}

 

Below is what the Loop output is:

 

 


1 reply

Userlevel 7
Badge +14

@pacedavis 

Try adding a Sub-Zap: https://help.zapier.com/hc/en-us/articles/8496308527629-Build-reusable-Sub-Zaps

Reply