//Info: SZCO-4
Solution:
We are going to include a new transaction line field in NetSuite. “ON ORDER” will be the field name, and a decimal number will be the field type. This field is used to display the quantity of the item that is “ON ORDER.” Based on the transaction body level location, the value for this field will be taken from the item record’s “ON ORDER” quantity.
define(['N/currentRecord', 'N/record', 'N/search'],
/**
* @param{currentRecord} currentRecord
* @param{record} record
* @param{search} search
*/
function (currentRecord, record, search) {
function validateLine(context) {
try {
if (context.sublistId == "item") {
var currentRecord = context.currentRecord;
var itemid = currentRecord.getCurrentSublistValue({sublistId: 'item', fieldId: 'item'});
var bodyLocationid = currentRecord.getValue({fieldId: 'location'});
if (itemid) {
//search for item warehouse count
var itemSearchObj = search.create({
type: "item",
filters:
[
["internalid", "anyof", itemid],
"AND",
["inventorylocation", "anyof", bodyLocationid]
],
columns:
[
search.createColumn({
name: "locationquantityonorder",
label: "Location On Order"
})
]
});
var obj = {};
itemSearchObj.run().each(function (result) {
obj.qtyOnOrder = result.getValue({
name: "locationquantityonorder",
label: "Location On Order"
});
return false;
});
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_jj_cs_on_order_cdu_4',
value: obj.qtyOnOrder,
ignoreFieldChange: false
}) || 0;
return true;
}
}
} catch (error) {
console.log("error @ Item Selected", error);
}
}
return {
validateLine: validateLine
};
});