Stock Rules

alm
Kilo Explorer

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 = vendor.

 

I then change the State from In Stock to In Use and assign it to myself and see that the item is no longer in the stockroom.

 

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

 

But the Manager receive now email or task as descriped in the wiki for this: http://wiki.servicenow.com/index.php?title=Stockrooms_and_Stock_Rules

 

Anyone have any idea whats missing.

1 ACCEPTED SOLUTION

Community Alums
Not applicable

The Stock Rule Runner Scheduled job runs once a day and is scheduled for 1 am on the instance's time by default. If you do not want to wait overnight, you can go to System Scheduler > Scheduled Jobs > Scheduled Jobs and find Stock Rule Runner. Set the Next action date/time to be in the past, and the job will run right away.



Ben


View solution in original post

6 REPLIES 6

Community Alums
Not applicable

The Stock Rule Runner Scheduled job runs once a day and is scheduled for 1 am on the instance's time by default. If you do not want to wait overnight, you can go to System Scheduler > Scheduled Jobs > Scheduled Jobs and find Stock Rule Runner. Set the Next action date/time to be in the past, and the job will run right away.



Ben


Hey Ben,


Doesn't seem like the "Vendor" type of Stock Rules do anything.   The scheduled job in our instance is only looking at stockroom transfer types and then doesn't do anything for vendor ones.   Is there a new scheduled job that does the other part?   We had touched the scheduled job previous to Calgary so it sees that its a customer update and we didn't ever get a new one.


Community Alums
Not applicable

Alan,


Did it used to work, or is this a new issue. There is logic in the scheduled job to create a Task for the Stockroom Manager to address the quantity of the item. I've been working with it since Calgary and it has worked in every version up through Helsinki.



Here is the latest script from the Stock Rule Runner Scheduled Job, I've set in bold the query that handles the vendor option:



gs.include('StockRuleTransfer');


              var transfer = new StockRuleTransfer();


             


              runStockRules();


              stockLevelThreshold();


             


              function runStockRules() {


             


                      var stockRules = new GlideRecord('alm_stock_rule');


                      stockRules.addQuery('active', 'true');


                      stockRules.addQuery('restocking_option', 'stockroom');


                      stockRules.query();


             


                      while (stockRules.next()) {


             


                              var parent = stockRules.parent_stockroom;


                              var stockroom = stockRules.stockroom;


                              var model = stockRules.model;


                              var supply = transfer.getTotalRecordCount(stockroom, model);


                              var thresh = parseInt(stockRules.threshold,10);


                              var need = thresh - supply;


                              var order = 0;


                              var size = parseInt(stockRules.order_size,10);


             


                              if (need > 0) {


             


                                      if(size <= 0) {


                                              order = need;


                                      } else {


                                              while (order < need)


                                                      order += size;


                                      }


             


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


                                      if (stock >= order) {


             


                                              if(model.sys_class_name == 'cmdb_consumable_product_model' || model.asset_tracking_strategy == 'track_as_consumable')


                                                      transfer.consumableTransfer(parent, stockroom, model, order);


                                              else


                                                      transfer.assetTransfer(parent, stockroom, model, order);


                                      }


                                      //if it does not have enough, it will run each night until the parent stockroom has enough supply


                              }


                      }


              }


             


              function stockLevelThreshold() {


                      /*


                      If quantity is below threshold and pending_delivery is false, send email & create task


                      If quantity is below threshold and pending_delivery is true, do nothing


                      If quantity is above threshold and pending_delivery is false, do nothing


                      If quantity is above threshold and pending_delivery is true, change pending_delivery to false


                      */


             


                      var stockLevel = new GlideRecord('alm_stock_rule');


                      stockLevel.addQuery('active', 'true');


                    stockLevel.addQuery('restocking_option', 'vendor');


                      stockLevel.query();


             


                    while (stockLevel.next()) {


             


                      var threshold = stockLevel.threshold;


                      var stockroom = stockLevel.stockroom;


                      var model = stockLevel.model;


                      var quantity = transfer.getTotalRecordCount(stockroom, model);


                      var manager_email = stockLevel.stockroom.manager.email;


                      var manager_name = stockLevel.stockroom.manager.name;


                      var size = parseInt(stockLevel.order_size,10);


             


                      // Quantity below threshold


                      if ((quantity < threshold) && stockLevel.pending_delivery != true) {


                              var need = threshold - quantity;


                              var order = 0;


             


                              if(size <= 0) {


                                      order = need;


                              } else {


                                      while (order < need)


                                      order += size;


                              }


             


                              // Trigger event


                              gs.eventQueue("asset.restock", stockLevel, order, threshold);


             


                              // Add task


                              var task = new GlideRecord('task');


                              task.initialize();


                              task.assigned_to = stockLevel.stockroom.manager;


                              task.short_description = 'Quantity threshold breached: '+ stockroom.name;


                              task.description = 'Stockroom: ' + stockroom.name + '\nItem: ' + model.display_name + '\nQuantity: ' + quantity + '\nThreshold: ' + threshold;


                              task.insert();


             


                              // Set "pending_delivery" to true


                              stockLevel.pending_delivery = "true";


                      }


             


                      // Quantity above threshold


                      else if ((quantity > threshold) && stockLevel.pending_delivery == true) {


                              stockLevel.pending_delivery = "false";


                      }


                      stockLevel.update();


                  }


}


It never worked, because I guess we modified the Scheduled Job back before Calgary and never got the new improved one.   Oh thanks for posting the new one!


I'll probably be modifying it anyways to create a REQ>RITM>sc_task instead of a normal task cause there's a cool RITM/sc_task to PO ui action I've created for our asset manager he'd like to use and that way the PO gets linked to a REQ instead of coming from some bland "task" type that isn't used by anything else.