Adding another element to an array

I have an array of collections containing product sales information e.g. product name, cost, tax, product id etc. The array has multiple products in it which will be used to create an invoice in Xero.

I need to add another item to this collection which has the shipping details for the order.

example code:
Array of product items:

[
    {
        "__IMTKEY__": 1,
        "array": [
            {
                "ID": 102,
                "TaxType": null,
                "Quantity": 4,
                "itemCode": null,
                "UnitAmount": "10.25",
                "lineItemID": null,
                "orderTotal": "41.00",
                "Description": "2472/2476-Half Caff",
                "DiscountRate": 0,
                "lineItemName": null,
                "websiteOrderNumber": 4279
            }
        ]
    }
]

And the shipping information:

[
    {
                "ID": 14,
                "TaxType": null,
                "Quantity": 1,
                "itemCode": null,
                "UnitAmount": "5.00",
                "lineItemID": null,
                "orderTotal": "5.00",
                "Description": "First Class Royal Mail",
                "DiscountRate": 0,
                "lineItemName": null,
                "websiteOrderNumber": null
     }
]

As the shipping info doesn’t have a collection name (which I’d thought I could have used add() function) how do I add the shipping info collection into the array?

1 Like

So I’ve managed to do it.

Essentially, the issue comes from not knowing how to create the bundle with a name so it can be merged with the original array using merge(). So I’ve created a new array using the aggregator module and then created another variable which uses the merge() function of the output with the source array I wanted to add these new variables into.

Also realised the bundle which is added to the array doesn’t need to directly match the source array which I wasn’t aware of before. I expected it to need to have the same key-value pairs to work.

3 Likes