Handlebar Syntax Help
Given this resource:
{
"data": [
[
{
"id": "6402565",
"recordType": "itemfulfillment",
"TrackingNumber": "593470228420",
"Ship Via": "FedEx Ground",
"ItemName": "WP36-HON-3P",
"Quantity": "1",
"Document Number": "IF120193",
"SellBrite Order Number": "13999",
"Carrier": "Standard"
},
{
"id": "6402565",
"recordType": "itemfulfillment",
"TrackingNumber": "593470228360",
"Ship Via": "FedEx Ground",
"ItemName": "WP36-HON-3P",
"Quantity": "1",
"Document Number": "IF120193",
"SellBrite Order Number": "13999",
"Carrier": "Standard"
}
]
]
}
And this template:
{
"shipment":
{{#each data}}
{{#if @index}} , {{/if}}
{
"sb_order_seq": {{this.0.[SellBriteOrderNumber]}},
"tracking_number": "{{this.0.TrackingNumber}}",
"carrier_name": "FedEx",
"tracking_url": "",
"warehouse_uuid": "b02fa8bc-9b01-43de-b9e7-f69ead1b9a98",
"shipping_method": "FedEx Ground",
"items": [
{{#each this}}
{{#if @index}} , {{/if}}
{
"sku": "{{ItemName}}",
"quantity": {{Quantity}}
}
{{/each}}
]
}
{{/each}}
}
I would like to output just one...
{
"sku": "{{ItemName}}",
"quantity": {{Quantity}}
}
...block but sum the {{Quantity}} for all iterations in the loop.
The host we are sending this to can't accept multpile tracking numbers for the same SKU so I want to add all quantities shipped to the first tracking number ({{this.0.TrackingNumber}})
Any thoughts?
0
Comments
I don't see how this can be done with handlebars because you basically need to regroup your data. It looks like this data is coming from NetSuite, could you group the data on the NetSuite saved search side? If you can get one tracking number tied to the item fulfillment on the result, then you could group by item and sum quantity. If that's not possible, I made a pre save page script that you could utilize.
Thanks Tyler I will give that a shot. I was having some issues getting the Netsuite saved search to report out the data in a way I could use it. The package contents are a custom record type under the fulfillment record and getting all the data the way I wanted proved difficult. I will give the preSavePage a shot, thanks!
Please sign in to leave a comment.