mg2017
02/16/2021, 4:24 PMNetsuite Tragic
02/16/2021, 9:03 PMmg2017
02/16/2021, 11:03 PMNetsuite Tragic
02/17/2021, 12:10 AM/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/error', 'N/log', 'N/record','N/runtime'],
function(error, log, record,runtime) {
const LINE_FIELD_INVENTORY_LOCATION = 'inventorylocation';
function soBeforeSubmit(scriptContext){
if(scriptContext.type == scriptContext.UserEventType.CREATE || scriptContext.type == scriptContext.UserEventType.EDIT){
try{
var headerLocation = scriptContext.newRecord.getValue({
fieldId: 'location'
});
var transactionSubsdiary = scriptContext.newRecord.getValue({
fieldId: 'subsidiary'
});
log.debug('transactionSubsdiary'+transactionSubsdiary);
//If the subsidiary is do this, otherwise do not execute.
if(transactionSubsdiary == 6 || transactionSubsdiary == 7 ){
//get the number if line is on the Sales Order
if (headerLocation){
var itemcount = scriptContext.newRecord.getLineCount({
sublistId: 'item'
});
log.debug('transactionSubsdiary:'+transactionSubsdiary+' Location ID:'+headerLocation+' No of lines:'+itemcount);
//get the existing line inventory location
for(var i = 0; i < itemcount; i++){
var lineLocation = scriptContext.newRecord.getSublistValue({
sublistId: 'item',
fieldId: LINE_FIELD_INVENTORY_LOCATION,
line: i
});
//update the line INventory Location if it does not match the header location.
if(lineLocation != headerLocation){
scriptContext.newRecord.setSublistValue({
sublistId: 'item',
fieldId: LINE_FIELD_INVENTORY_LOCATION,
line: i,
value: headerLocation
});
}
}
}
}
}
catch(e){
log.debug(e.name,e.message);
}
}
}
return {
beforeSubmit: soBeforeSubmit
};
});
mg2017
02/17/2021, 12:32 AMmg2017
02/17/2021, 1:01 AMNetsuite Tragic
02/17/2021, 3:01 AM