define(['N/currentRecord', 'N/record'],
/**
* @param{currentRecord} currentRecord
* @param{record} record
*/
function(currentRecord, record) {
/**
* Function to be executed when field is changed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
* @param {string} scriptContext.fieldId - Field name
* @param {number} scriptContext.lineNum - Line number. Will be undefined if not a sublist or matrix field
* @param {number} scriptContext.columnNum - Line number. Will be undefined if not a matrix field
*
* @since 2015.2
*/
function fieldChanged(scriptContext) {
try {
var currentRecord = scriptContext.currentRecord;
if (scriptContext.sublistId == 'item' && scriptContext.fieldId == 'custcol_jj_customquantity' ) {
var status = currentRecord.getValue({
fieldId: 'status'
})
console.log('status', status);
if (status == 'Pending Fulfillment' || 'Partially Fulfilled' || 'Pending Receipt/Partially Fulfilled'){
var qtyBackOrd = currentRecord.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantitybackordered'
});
var qtyPicked = currentRecord.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantitypicked'
});
var qtyOrdered = currentRecord.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity'
});
var qtyCommitted = currentRecord.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantitycommitted'
});
var qtyShipped = currentRecord.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantityfulfilled' || 0
});
var newQty = currentRecord.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_jj_customquantity'
});
console.log('newQty', newQty);
if (qtyPicked > 0 && newQty > 0) {
if (newQty < qtyPicked) {
alert("Items on this line have been picked, you cannot enter a value which is less than the picked quantity.")
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_jj_customquantity',
value: ""
});
} else if (newQty > qtyOrdered) {
var messageText = confirm("You have only " + qtyCommitted + " available for commitment at this location. You cannot enter a value greater than the current ordered quantity")
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_jj_customquantity',
value: ""
});
}
else {
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: newQty
});
}
} else {
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_jj_customquantity',
value: ""
});
}
}
}
}catch (e) {
log.debug("error @ field changed", e.message);
}
}
return {
fieldChanged: fieldChanged
};
});