Sunny R
03/24/2023, 6:03 PMStuart Anderton
03/25/2023, 8:44 AMSunny R
03/25/2023, 2:02 PM/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
define(['N/record', 'N/search'], function(record, search) {
function execute(context) {
// Load the item record
var itemRecord = record.load({
type: record.Type.INVENTORY_ITEM,
id: 10336,
isDynamic: false,
});
// Get the out-of-stock behavior
var outOfStockBehavior = itemRecord.getValue({
fieldId: 'outofstockbehavior'
});
var quantityAvailable = itemRecord.getValue({
fieldId: 'quantityavailable'
});
// Set the out-of-stock behavior based on the quantity available
if (quantityAvailable > 0) {
itemRecord.setValue({
fieldId: 'outofstockbehavior',
value: record.FieldValue.ENABLE
});
} else {
itemRecord.setValue({
fieldId: 'outofstockbehavior',
value: record.FieldValue.DISABLE
});
}
// Save the item record
itemRecord.save();
// Log the out-of-stock behavior
log.debug({
title: 'Item Out-of-Stock Behavior',
details: 'Item ID: 10336, Out-of-Stock Behavior: ' + outOfStockBehavior
});
}
return {
execute: execute
};
});Stuart Anderton
04/01/2023, 8:03 AM