Requirement
We need to introduce a soft warning pop-up when users attempt to Save an Inventory Transfer which will result in Negative Stock being recorded at the From Location.
- The criteria for triggering this pop-up are:
- One or more line items have a ‘QTY. ON HAND’ (From Location) value which is LESS THAN then ‘QTY. TO TRANSFER’ value
Solution
We can use client script save record function to display a pop up warning message.
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/currentRecord', 'N/record', 'N/search'],
/**
* @param{currentRecord} currentRecord
* @param{record} record
* @param{search} search
*/
function (currentRecord, record, search) {
function saveRecord(scriptContext) {
try {
//Get the current record
var currentRec = scriptContext.currentRecord
//Get the line count of inventory lines
var line_count = currentRec.getLineCount({
sublistId: 'inventory'
});
//Looping through the inventory lines
for (var i = 0; i < line_count; i++) {
//Get the quantity On Hand
var quantityonhand = currentRec.getSublistValue({
sublistId: 'inventory',
fieldId: 'quantityonhand',
line: i
});
log.debug('quantityonhand', quantityonhand)
//Get the Quantity to transfer
var adjustqtyby = currentRec.getSublistValue({
sublistId: 'inventory',
fieldId: 'adjustqtyby',
line: i
});
log.debug('adjustqtyby', adjustqtyby)
//If the quantity on hand value is less than the quantity to transfer value then show the pop message
if (Number(quantityonhand) < Number(adjustqtyby)) {
if(confirm('This Inventory Transfer contains one or more lines which will create Negative Stock at the From Location. You should make efforts to resolve this Negative Stock before continuing')){
return true
}
else{
return false
}
}
}
return true
} catch (e) {
log.debug('Error@SaveRecord', e)
}
}
return {
saveRecord: saveRecord
};
});