Rywin
04/21/2022, 7:43 AMbattk
04/21/2022, 7:50 AMRywin
04/21/2022, 7:55 AMconst beforeSubmit = (scriptContext) => {
var LogTitle = 'beforeSubmit';
log.debug(LogTitle, LogTitle + LOG_START);
//Get Type IF CREATE
if(scriptContext.type == 'create'){
var SORec = scriptContext.newRecord;
//Get Subsidiary
var Subs = SORec.getValue({
fieldId : 'subsidiary'
});
//IF Subsidiary is CFS
if(Subs == '1'){
//Get IF UI
var ctx = runtime.executionContext;
if(ctx == "USERINTERFACE"){
//Get IF Intecompany
var Interco = SORec.getValue({
fieldId : 'intercotransaction'
});
if(!Interco){
//Get Sales Rep ID
var sALESrEP = SORec.getValue({
fieldId : 'salesrep'
})
//Get Sales Rep Team
var emp_team = search.lookupFields({
type : search.Type.EMPLOYEE,
id : sALESrEP,
columns : 'custentity3'
});
log.debug('TEAM',emp_team);
//Get Item Line Count
var count = SORec.getLineCount({
sublistId : 'item'
});
for(var x = 0; x < count; x++){
//Get Item ID
var ItemID = SORec.getSublistValue({
sublistId : 'item',
fieldId : 'item',
line : x
});
log.debug('Item ' + x, JSON.stringify(ItemID));
//Get Item Type
var ItemType = SORec.getSublistValue({
sublistId : 'item',
fieldId : 'itemtype',
line : x
});
//IF Inventory
if(ItemType == 'InvtPart'){
//Get Item Name/Code
var LookItem = search.lookupFields({
type : search.Type.INVENTORY_ITEM,
id : ItemID,
columns : 'itemid'
});
SORec.setSublistText({
sublistId : 'item',
fieldId : 'item',
line : x,
text : LookItem.itemid
})
var ItemCode = SORec.getSublistText({
sublistId : 'item',
fieldId : 'item',
line : x
});
//Get Item Quantity
var qty = SORec.getSublistValue({
sublistId : 'item',
fieldId : 'quantity',
line : x
});
//Get Location
var loc = SORec.getSublistValue({
sublistId : 'item',
fieldId : 'location',
line : x
});
//Get If Closed
var closed = SORec.getSublistValue({
sublistId : 'item',
fieldId : 'isclosed',
line : x
});
//If Closed and Not Dropship Loc
if(loc !== '246'){
if(closed == 'F' || closed == false || closed == null){
//Load Item Record
var ItemRec = record.load({
type : record.Type.INVENTORY_ITEM,
id : ItemID
});
//Get Item QS
var QS = ItemRec.getValue({
fieldId : salesrep_itemfld_map[emp_team["custentity3"][0].value].qs
});
//Get Item SL
var SL = ItemRec.getValue({
fieldId : salesrep_itemfld_map[emp_team["custentity3"][0].value].ts
});
//Round Off QS / SL
QS = Math.round( parseFloat(QS) * 100) / 100;
SL = Math.round( parseFloat(SL) * 100) / 100;
//Get new QS
var RUE = parseFloat(QS) + parseFloat(qty);
//Get Remaining
var Rem = parseFloat(SL) - parseFloat(QS);
//If Selling Limit
if(parseFloat(RUE) > parseFloat(SL)){
//Create Error
var SL_CREATE = error.create({
message : salesrep_itemfld_map[emp_team["custentity3"][0].value].id + ' -- Item:'+ " " + ItemCode + " --" + 'Quantity Sold exceeds Selling Limit.Please contact Merchandising Department for adjustments.' + "\n" + "\n" + 'Mayroon ka na lamang ' + Rem + ' kgs na maaaring ibenta para dito ☺',
name : 'SL_CREATE',
notifyOff : true
});
//Throw Error
throw SL_CREATE.message;
}
}
}
}
}
}
}
}
}
}
@battkbattk
04/21/2022, 7:57 AMRywin
04/21/2022, 7:58 AMbattk
04/21/2022, 7:59 AMRywin
04/21/2022, 8:03 AMbattk
04/21/2022, 8:04 AMvar SORec = scriptContext.newRecord;
var Subs = SORec.getValue({
fieldId: "subsidiary",
});
if (scriptContext.type !== "create" || Subs !== "1") {
return;
}
Rywin
04/21/2022, 8:05 AMbattk
04/21/2022, 8:05 AMSORec.setSublistText({
sublistId: "item",
fieldId: "item",
line: x,
text: LookItem.itemid,
});
Rywin
04/21/2022, 8:07 AMbattk
04/21/2022, 8:10 AMRywin
04/21/2022, 8:11 AM