When the Supply Allocation feature is enabled “DO NOT ALLOCATE” showcases the same functionality of “Do not Commit” in Sales Order. By setting “DO NOT ALLOCATE” in back-ordered item lines, whenever stock comes in the future it won’t get committed in these Back-ordered lines.
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
******************************************************************************************************
Sript Description: Make 'Backordered' lines as DO NOT ALLOCATE
*******************************************************************************************
**********/
define(['N/format', 'N/url', 'N/search', 'N/runtime', 'N/record', 'N/https', 'N/ui/serverWidget'],
function (format, url, search, runtime, record, https, serverWidget) {
var main = {
afterSubmit: function (scriptContext) {
var newRecId = scriptContext.newRecord.id;
log.debug('newRecId', newRecId);
var soRec = record.load({
type: "salesorder",
id: newRecId,
isDynamic: false
})
var subStatus = soRec.getValue({
fieldId: "subsidiary"
})
var orderStatus = soRec.getValue({
fieldId: "custbody_order_sent"
})
log.debug('orderStatus', orderStatus);
if (orderStatus == true && subStatus == 1) {
var numLines = soRec.getLineCount({
sublistId: 'item'
});
if (numLines > 0) {
for (var i = 0; i < numLines; i++) {
var backqty = soRec.getSublistValue({
sublistId: 'item',
fieldId: 'quantitybackordered',
line: i
});
if (backqty > 0) {
soRec.setSublistValue({
sublistId: 'item',
fieldId: 'orderallocationstrategy',//'commitinventory',
line: i,
value: ''//3
});
}
}
}
var saveID = soRec.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
log.debug("savecontext", saveID);
}
}
}
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.error("e in " + key, e);
return false;
}
}
};
return main;
});