Fulfillment Discrepancy – Mearsk Integration

The root cause lies in how parent-child items are handled during the comparison process. In the response from Maersk, the item name is provided without the parent reference. As a result, the script fails to match the items correctly. In these cases, the Item Fulfillment is created by transforming the Sales Order into Item Fulfillment, which is why the item ‘HCNAS102299’ was included in the Item Fulfilment IF-304286.

createItemFulfillment(jsonRequest, orderType, transactionId, customRecordId, locationId) {
let returnObj = {};
try {
// converting array of objects to objects of object (ItemInfo of Pack request)
let finalDataToFulfill = PROCESS.finalFulfillmentProcessData(jsonRequest.Request.Sales_Order_Pack.PackDetailInfo.ItemInfo);
let ifRec, fulfillCheck = true, available;
if (orderType == "SalesOrd" || orderType == "TrnfrOrd") {
let checkCommitment = DATASETS.fetchOrderDetails(jsonRequest.Request.Sales_Order_Pack.ExternDocId, orderType);
if (Object.entries(finalDataToFulfill).length > 0) {
for (let key in finalDataToFulfill) {
let nsItemLine = checkCommitment[key];
if (nsItemLine.availableQuantity.value < finalDataToFulfill[key].ItemQty) {
available = false;
break;
}
else {
available = true;
}
}
}
// Sales order into Item Fulfillment
if (orderType == "SalesOrd") {
if (available == true) { //When commitment available
ifRec = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: transactionId,
toType: record.Type.ITEM_FULFILLMENT,
defaultValues: {
inventorylocation: Number(locationId)
}
});
}
else {
ifRec = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: transactionId,
toType: record.Type.ITEM_FULFILLMENT,
});
}
}
// Transfer Order into Item Fulfillment
else if (orderType == "TrnfrOrd") {
if (available == true) { //When commitment available
ifRec = record.transform({
fromType: record.Type.TRANSFER_ORDER,
fromId: transactionId,
toType: record.Type.ITEM_FULFILLMENT,
defaultValues: {
inventorylocation: Number(locationId)
}
});
}
else {
ifRec = record.transform({
fromType: record.Type.TRANSFER_ORDER,
fromId: transactionId,
toType: record.Type.ITEM_FULFILLMENT,
});
}
}
}
if (orderType == "VendAuth") {
// Vendor return authorization into Item Fulfillment
ifRec = record.transform({
fromType: record.Type.VENDOR_RETURN_AUTHORIZATION,
fromId: transactionId,
toType: record.Type.ITEM_FULFILLMENT,
});
}
// Setting status as Packed
ifRec.setValue({ fieldId: "shipstatus", value: "B" });
let itemCount = ifRec.getLineCount({ sublistId: 'item' });
for (let i = 0; i < itemCount; i++) {
let itemLine = ifRec.getSublistValue({
sublistId: 'item',
fieldId: 'orderline',
line: i
});
let itemId = ifRec.getSublistText({
sublistId: 'item',
fieldId: 'itemname',
line: i
});
let itemParts = itemId.split(':');
// Extract the last element from the array
itemId = itemParts[itemParts.length - 1].trim();
let itemQuantity = ifRec.getSublistValue({
sublistId: 'item',
fieldId: 'quantity',
line: i
});
if (orderType == "TrnfrOrd") {
itemLine = itemLine - 1;
}
// When item lines are available in NetSuite
if (finalDataToFulfill[itemLine]) {
if (itemId == finalDataToFulfill[itemLine].ItemId) {
if (finalDataToFulfill[itemLine].ItemQty <= itemQuantity) {
ifRec.setSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: finalDataToFulfill[itemLine].ItemQty,
line: i
});
} else {
fulfillCheck = false;
returnObj.status = "FAILUE";
returnObj.message = "PACK_QUANTITY_IS_GREATER_THAN_ORDER_QUANTITY_AT_LINE :" + (i + 1) + " FOR_ITEM " + itemId;
break;
}
} else {
fulfillCheck = false;
returnObj.status = "FAILUE";
returnObj.message = "ITEM_NOT_FOUND_IN_RELATED_TRANSACTION_AT_LINE :" + (i + 1);
break;
}
}
else {
ifRec.setSublistValue({
sublistId: 'item',
fieldId: 'itemreceive',
value: false,
line: i
});
}
}
// Save Item Fulfillment when above conditions satisfied
if (fulfillCheck) {
returnObj.itemFulfillmentId = ifRec.save({
enableSourceing: true,
ignoreMandatoryFields: true
});
// Fetch Item Fulfillment Document Number
returnObj.itemFulfillmentDocNum = search.lookupFields({
type: "itemfulfillment",
id: returnObj.itemFulfillmentId,
columns: ["tranid"]
}).tranid;
// Check for Multiple Item Fulfillments for the current order
if (returnObj.itemFulfillmentId) {
let customRecordObj = search.lookupFields({
type: "customrecord_jj_cr_maersk_integrtn_info",
id: customRecordId.toString(),
columns: ["custrecord_jj_item_fulfillment_micl300"]
});
let itemFulfillmentArray = [];
if (
maerskUtility.checkForParameter(customRecordObj["custrecord_jj_item_fulfillment_micl300"]) &&
customRecordObj["custrecord_jj_item_fulfillment_micl300"].length != 0
) {
for (let i = 0; i < customRecordObj["custrecord_jj_item_fulfillment_micl300"].length; i++) {
itemFulfillmentArray.push(customRecordObj["custrecord_jj_item_fulfillment_micl300"][i].value);
}
itemFulfillmentArray.push(returnObj.itemFulfillmentId);
}
else {
itemFulfillmentArray.push(returnObj.itemFulfillmentId);
}
// Saving Item fulfillment to custom record - Maersk Integration Info
record.submitFields({
type: "customrecord_jj_cr_maersk_integrtn_info",
id: customRecordId.toString(),
values: {
"custrecord_jj_item_fulfillment_micl300": itemFulfillmentArray,
"custrecord_jj_error_if_micl300": "",
"custrecord_jj_maersk_pack_json_micl300": JSON.stringify(jsonRequest)
},
options: {
enablesourcing: false,
ignoreMandatoryFields: true
}
});
// Setting the Maersk IF Sync checkbox as checked in IF record
record.submitFields({
type: record.Type.ITEM_FULFILLMENT,
id: returnObj.itemFulfillmentId,
values: {
"custbody_jj_maersk_if_sync_micl300": true,
},
options : {
enableSourceing : false,
ignoreMandatoryFields : true
}
});
}
}
return returnObj;
}
catch (e) {
log.error("Error@createItemFulfillment", e);
returnObj.status = "FAILUE";
returnObj.message = "RECORD_NOT_CREATED";
PROCESS.storeError(customRecordId, e.message);
return responseObj;
}
},


Leave a comment

Your email address will not be published. Required fields are marked *