This code will help to get only selected items from the item receipt before submit context from the item sublist.
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define([ 'N/record'],
function(record) {
var main = {
beforeSubmit: function(scriptContext) {
if (scriptContext.type == "create" || scriptContext.type == "edit") {
log.debug("scriptContext.type ", scriptContext.type);
var records = scriptContext.newRecord;
var itemadjustment = {};
itemadjustment.type = records.type;
itemadjustment.itemdetails = main.gettheitems(records, records.type);
},
gettheitems: function(recid, rectype) {
//log.debug("recid ", recid);
log.debug("rectype ", rectype);
var loadrec = recid;
var Tranid = loadrec.getValue({
fieldId: 'tranid'
});
if (rectype == "itemreceipt") {
var sublisttype = "item";
var numLines = loadrec.getLineCount({
sublistId: sublisttype
});
}
var itemLocationObj={};
for (var i = 0; i < numLines; i++) {
var itemLocation =loadrec.getSublistValue({
sublistId: sublisttype,
fieldId: 'location',
line: i
});
var quantRecived =loadrec.getSublistValue({
sublistId: sublisttype,
fieldId: 'itemreceive',
line: i
});
if(quantRecived == true){
if(!itemLocationObj[itemLocation])
itemLocationObj[itemLocation]=[];
itemLocationObj[itemLocation].push(loadrec.getSublistValue({ sublistId: sublisttype,fieldId: 'item',line: i}))
}
}
log.debug("itemLocationObj",itemLocationObj)
return {
recdataarray: itemLocationObj,
Tranid: Tranid
}
},
};
for (var key in main) {
if (typeof main[key] === 'function') {
main[key] = trycatch(main[key], key);
}
}
function trycatch(myfunction, key) {
return function() {
try {
return myfunction.apply(this, arguments);
} catch (e) {
log.debug("e in " + key, e);
}
}
};
return main;
});