Micah
11/04/2021, 8:04 PMbattk
11/04/2021, 8:11 PMMicah
11/04/2021, 9:42 PMMicah
11/04/2021, 9:47 PM/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define(['N/record','N/search'],
function (record,search) {
function afterSubmit(context) {
try {
var itemFulfillment = context.newRecord;
//Pull ShipHawk service text
var shipHawkCarrierService = itemFulfillment.getValue('custbody_shiphawk_carrier_service');
if(shipHawkCarrierService != ''){
log.debug({
title: 'ShipHawk Carrier Service',
details: shipHawkCarrierService
})
//Run saved search - mappings of ShipHawk Shipping Methods and their NetSuite counterparts
var mapSearch = search.load({
id: 'customsearch_sh2ns_shipping_method_map'
})
var resultSet = mapSearch.run();
resultSet.each(function(result){
var shipHawkCarrier = result.getValue(result.columns[0]);
var shipHawkService = result.getValue(result.columns[1]);
var netSuiteShipMethod = result.getValue(result.columns[2]);
//Find the mapping where the current ShipHawk method matches
if (shipHawkCarrierService == shipHawkService){
var methodId;
log.debug({
title:'Equal',
details: netSuiteShipMethod
})
//Search for NetSuite ship_item record to return internalID
var methodSearch = search.load({
id:'customsearch_ship_items_shiphawk'
})
var methodResultSet = methodSearch.run();
methodResultSet.each(function(methodResult){
var internalId = methodResult.getValue(methodResult.columns[0]);
var methodName = methodResult.getValue(methodResult.columns[1]);
if(methodName == netSuiteShipMethod){
methodId = internalId;
}
return true;
})
//Load ship_item object by internalID
var methodObject = record.load({
type:'shipitem',
id:methodId,
isdynamic:true
})
var carrier = (shipHawkCarrier == 'UPS' ? 'UPS' : 'FedEx/USPS/More');
//Update fields within Item Fulfillment
var id = record.submitFields({
type: 'itemfulfillment',
id: itemFulfillment.id,
values: {
'shipcarrier':carrier,
'shipmethod':methodObject
}
})
return;
}
return true;
})
}
} catch (e) {
log.debug({
title: 'Error Details',
details: e
})
}
}
return {
afterSubmit: afterSubmit
};
}
);
battk
11/04/2021, 9:58 PMbattk
11/04/2021, 9:58 PMbattk
11/04/2021, 9:58 PMbattk
11/04/2021, 9:58 PMbattk
11/04/2021, 9:58 PMbattk
11/04/2021, 9:59 PMbattk
11/04/2021, 10:00 PMbattk
11/04/2021, 10:01 PMbattk
11/04/2021, 10:02 PMMicah
11/05/2021, 11:55 AMStephan Vagner
11/22/2021, 4:34 AM