Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

stock rules

chercm
Mega Sage

I have setup a stockroom and assigned a manager (and the manager has an email address) I have added an item into the stockroom.

 

Then I have setup a stock rule for the item with a Threshold = 0 and a Restock Option = stock room

 

So now there are 0 in stock and the stock rule should kick in.

 

i tried to change the next action date on the stock rule running but still not getting the sctask created . any idea how to fix this ?

1 ACCEPTED SOLUTION

i found the solution too . to add this part that if the restocking option is set to stockroom , there will be task ticket assigned to the stockroom manager

_processStockoomStockrule: function(stockRuleGr) {
var parent = stockRuleGr.parent_stockroom;
var stockroom = stockRuleGr.stockroom;
var model = stockRuleGr.model;
var supply = this.transfer.getTotalRecordCount(stockroom, model);
var threshold = parseInt(stockRuleGr.threshold, 10);
var need = threshold - supply;
var order = 0;
var size = parseInt(stockRuleGr.order_size, 10);

if (need > 0) {
if (size <= 0) {
order = need;
} else {
while (order < need) {
order += size;
}
}

var stock = this.transfer.checkStockroomTransferAvailability(parent, model);

if (stock >= order) {
if (model.sys_class_name.toString() === this.CONS_MODEL
|| model.asset_tracking_strategy.toString() === this.TRACK_CONS) {
this.transfer.consumableTransfer(parent, stockroom, model, order);
} else {
this.transfer.assetTransfer(parent, stockroom, model, order);
}

// ✅ Set pending_delivery to true
stockRuleGr.pending_delivery = 'true';
stockRuleGr.update();

// ✅ Create a Task for Asset Manager with requested format
var task = new GlideRecord('task');
task.initialize();
task.assigned_to = stockroom.manager; // Assign to stockroom manager
task.short_description = 'Quantity threshold breached: ' + stockroom.name;
task.description = 'Stockroom: ' + stockroom.name + '\nItem: ' + model.display_name +
'\nQuantity: ' + supply + '\nThreshold: ' + threshold;
task.insert();
} else {
// ✅ If stock is unavailable, create a task for asset manager to take action
var task = new GlideRecord('task');
task.initialize();
task.assigned_to = stockroom.manager;
task.short_description = 'Quantity threshold breached: ' + stockroom.name;
task.description = 'Stockroom: ' + stockroom.name + '\nItem: ' + model.display_name +
'\nQuantity: ' + supply + '\nThreshold: ' + threshold +
'\nParent Stockroom: ' + parent.name + '\nRequired: ' + order +
'\nAvailable in Parent: ' + stock;
task.insert();
}
}
}, 

View solution in original post

10 REPLIES 10

i found the solution too . to add this part that if the restocking option is set to stockroom , there will be task ticket assigned to the stockroom manager

_processStockoomStockrule: function(stockRuleGr) {
var parent = stockRuleGr.parent_stockroom;
var stockroom = stockRuleGr.stockroom;
var model = stockRuleGr.model;
var supply = this.transfer.getTotalRecordCount(stockroom, model);
var threshold = parseInt(stockRuleGr.threshold, 10);
var need = threshold - supply;
var order = 0;
var size = parseInt(stockRuleGr.order_size, 10);

if (need > 0) {
if (size <= 0) {
order = need;
} else {
while (order < need) {
order += size;
}
}

var stock = this.transfer.checkStockroomTransferAvailability(parent, model);

if (stock >= order) {
if (model.sys_class_name.toString() === this.CONS_MODEL
|| model.asset_tracking_strategy.toString() === this.TRACK_CONS) {
this.transfer.consumableTransfer(parent, stockroom, model, order);
} else {
this.transfer.assetTransfer(parent, stockroom, model, order);
}

// ✅ Set pending_delivery to true
stockRuleGr.pending_delivery = 'true';
stockRuleGr.update();

// ✅ Create a Task for Asset Manager with requested format
var task = new GlideRecord('task');
task.initialize();
task.assigned_to = stockroom.manager; // Assign to stockroom manager
task.short_description = 'Quantity threshold breached: ' + stockroom.name;
task.description = 'Stockroom: ' + stockroom.name + '\nItem: ' + model.display_name +
'\nQuantity: ' + supply + '\nThreshold: ' + threshold;
task.insert();
} else {
// ✅ If stock is unavailable, create a task for asset manager to take action
var task = new GlideRecord('task');
task.initialize();
task.assigned_to = stockroom.manager;
task.short_description = 'Quantity threshold breached: ' + stockroom.name;
task.description = 'Stockroom: ' + stockroom.name + '\nItem: ' + model.display_name +
'\nQuantity: ' + supply + '\nThreshold: ' + threshold +
'\nParent Stockroom: ' + parent.name + '\nRequired: ' + order +
'\nAvailable in Parent: ' + stock;
task.insert();
}
}
},