Amazon Dropship 856

Amazon Dropship (ISA ID: AMAZONDS) leverages a unique 856 HL structure. The following JSONata template can be applied to convert the 856 to the required Order, Item, Pack structure for Amazon DS.

Additional modifications may be required depending on your NetSuite configuration and customizations.

(
  /* Assign variables for the various HL loops */
  $allLoops := $defaultValues.message.transactionSets[0].HL_loop;
  /* Shipment loop*/
  $sLoops := $allLoops[hierarchicalLevel.hierarchicalLevelCode = "S"];
  /* Order loops */
  $oLoops := $allLoops[hierarchicalLevel.hierarchicalLevelCode = "O"];
  /* Pack loops */
  $pLoops := $allLoops[hierarchicalLevel.hierarchicalLevelCode = "P"];
  /* Item loops */
  $iLoops := $allLoops[hierarchicalLevel.hierarchicalLevelCode = "I"];
  
  $asnTime := $defaultValues.message.transactionSets[0].beginningSegmentForShipNotice.time;
  
  {
  "sender" : $defaultValues.sender,
  "receiver": $defaultValues.receiver,
  "type": $defaultValues.type,
  "stream": $defaultValues.stream,
    "message": {
        "transactionSets": [{
            "beginningSegmentForShipNotice" : $defaultValues.message.transactionSets[0].beginningSegmentForShipNotice,
            "HL_loop": [
                /* Order level */
                {
                    "hierarchicalLevel": [{
                        "hierarchicalIDNumber": "1",
                        "hierarchicalLevelCode": "O"
                    }],
                    "purchaseOrderReference":[{
                      "purchaseOrderNumber" : $oLoops.purchaseOrderReference.purchaseOrderNumber,
                      "contractNumber": salesOrders[0].tranid
                    }],
                    /* Get the Ship From from the Shipment Loop */
                    "N1_loop": [$sLoops.N1_loop[partyIdentification.entityIdentifierCode="SF"]]
                },
                /* Item levels with their Packs */
                $map(
                    $distinct($iLoops.itemIdentification.productServiceID),
                    function($productId, $idx) {(
                        /* Create an array with the Item followed by its Packs */
                        [
                            /* Item Loop*/
                            {
                                "hierarchicalLevel": [{
                                    "hierarchicalIDNumber": ($idx + 2) & "",
                                    "hierarchicalParentIDNumber": "1",
                                    "hierarchicalLevelCode": "I"
                                }],
                                "itemIdentification": [
                                  $iLoops[$idx].itemIdentification
                                ],
                                "itemDetailShipment": [{
                                    "assignedIdentification": $iLoops[$idx].itemDetailShipment.assignedIdentification,
                                    "numberOfUnitsShipped": $sum($map($iLoops[itemIdentification.productServiceID = $productId].itemDetailShipment, function($i) { $number($i.numberOfUnitsShipped) })) & "",
                                    "unitOrBasisForMeasurementCode": $iLoops[$idx].itemDetailShipment.unitOrBasisForMeasurementCode,
                                    "quantity": $iLoops[$idx].itemDetailShipment.quantity,
                                    "unitOrBasisForMeasurementCode1": $iLoops[$idx].itemDetailShipment.unitOrBasisForMeasurementCode1,
                                    "lineItemStatusCode": $iLoops[$idx].itemDetailShipment.lineItemStatusCode
                                }],
                                /*Grab the MAN from the parent pack(s)*/
                                "marksAndNumbersInformation": [$map(
                                  $iLoops[$idx],
                                  function($packItem, $i) {
                                    {
                                      "marksAndNumbersQualifier":"R",
                                      /*Vendor assigned package ID - Must match the Item loop marksAndNumbers*/
                                      "marksAndNumbers" : $pLoops[hierarchicalLevel.hierarchicalIDNumber = $packItem.hierarchicalLevel.hierarchicalParentIDNumber].marksAndNumbersInformation.marksAndNumbers
                                    }
                                })]
                            }, 
                            /* Packs for this Item */
                            $map(
                                $iLoops[itemIdentification.productServiceID = $productId],
                                function($packItem, $packIdx) {
                                    {
                                        "hierarchicalLevel": [{
                                            "hierarchicalIDNumber": (
                                                2 + 
                                                $count($distinct($iLoops.itemIdentification.productServiceID)) + 
                                                $sum($map(
                                                    $distinct($iLoops.itemIdentification.productServiceID),
                                                    function($v, $i) {
                                                        $v < $productId ? $count($iLoops[itemIdentification.productServiceID = $v]) : 0
                                                    }
                                                )) + 
                                                $packIdx
                                            ) & "",
                                            "hierarchicalParentIDNumber": ($idx + 2) & "",
                                            "hierarchicalLevelCode": "P"
                                        }],
                                        "carrierDetailsQuantityAndWeight":[
                                          $pLoops[hierarchicalLevel.hierarchicalIDNumber = $packItem.hierarchicalLevel.hierarchicalParentIDNumber].carrierDetailsQuantityAndWeight
                                        ],
                                        "carrierDetailsRoutingSequenceTransitTime":[
                                          $pLoops[hierarchicalLevel.hierarchicalIDNumber = $packItem.hierarchicalLevel.hierarchicalParentIDNumber].carrierDetailsRoutingSequenceTransitTime
                                        ],
                                        "marksAndNumbersInformation":[
                                          {
                                            "marksAndNumbersQualifier":"R",
                                            /*Vendor assigned package ID - Must match the Item loop marksAndNumbers*/
                                            "marksAndNumbers" : $pLoops[hierarchicalLevel.hierarchicalIDNumber = $packItem.hierarchicalLevel.hierarchicalParentIDNumber].marksAndNumbersInformation.marksAndNumbers,
                                            /*Manifest Number: Update logic accordingly*/
                                            "marksAndNumbers1" : $pLoops[hierarchicalLevel.hierarchicalIDNumber = $packItem.hierarchicalLevel.hierarchicalParentIDNumber].marksAndNumbersInformation.marksAndNumbers,
                                            /*Additional logic may be needed here for LTL or BOL support. Use CP for small parcel and SP for BOL or LTL*/
                                            "marksAndNumbersQualifier1":"CP",
                                            "marksAndNumbers2" : $pLoops[hierarchicalLevel.hierarchicalIDNumber = $packItem.hierarchicalLevel.hierarchicalParentIDNumber].marksAndNumbersInformation.marksAndNumbers
                                          }
                                        ],
                                        "dateTimeReference":[
                                          {
                                            "dateTimeQualifier":"011",
                                            "date":$sLoops.dateTimeReference[dateTimeQualifier="011"].date,
                                            /*Needs to be converted to Greenwich Mean Time via Rules or here*/
                                            "time":$defaultValues.message.transactionSets[0].beginningSegmentForShipNotice.time,
                                            "timeCode":"GM"
                                          },
                                          {
                                            "dateTimeQualifier":"ZZZ",
                                            "date":$sLoops.dateTimeReference[dateTimeQualifier="011"].date,
                                            /*Needs to be converted to Greenwich Mean Time via Rules or here*/
                                            "time": $defaultValues.message.transactionSets[0].beginningSegmentForShipNotice.time,
                                            "timeCode":"GM"
                                          }
                                        ]
                                    }
                                }
                            )
                        ]
                    )}
                )
            ]
        }]
    }
})