Script include "processstockrules"

anvitha ash
Tera Contributor

Hello community,

 

can someone explain what's happening with this script include "processstockrules"

1000323143.jpg

Thanks in advance 

3 REPLIES 3

JaishreeR
Giga Guru

Hi @anvitha ash ,

 

From the image what I can understand is that the script is used to process stock rules in batches, log the progress and results and it is used for tracking and executing stock-related activities. 

Line 1 of the code : Creating class

Line 2 of the code : Extending the class, inheriting its methods and properties 

Line 3-6 of the code : Defining the constants

a)CONS_MODEL: model name for consumable products

b)TRACK_CONS: to track the type of consumable 

c)HARDWARE_INVENTORY_STOCK_ORDER: sys_id of the hardware inventory stock order

d) ENTERPRISE_STOCK_ORDER_CAT_ITEM: sys_id of the enterprise stock order catalog item.

line 7 of the code : initialize the function

line 8 of the code : Initialize the stock transfer rules function and it handles the movement of stock according to defined rules

line 9 of the code : initialize the logging utility and used to track the progress and status of the job for auditing or debugging purpose

line 10- 18 : It is for tracking the Work ex: setting up a checklist to track the job:

  • Name of the job ("Stock Rule Runner").
  • How many tasks need to be done.
  • How many are for stockrooms or for vendors.
  • Whether the job finished or failed.

In simple words : 

The code begins by categorizing and tracking consumable items ex: paper or cleaning supplies using a model called cmdb_consumable_product_model. Assume these items need frequent restocking, and this model helps the system monitor them efficiently. Next, they have created two types of stock orders: Hardware Inventory Stock Orders and Enterprise Stock Orders. The Hardware Inventory Stock Orders could be for internal items like restocking office storerooms with printer paper, toner etc. The Enterprise Stock Orders, on the other hand, handle large-scale orders like laptops for a new project or other big purchases for the entire company.

Then the system kicks into action with the logging feature. As the Stockroom Rule processes, it handles tasks related to internal restocking. So, if the storerooms are low on supplies, the system ensures they get replenished. At the same time, it keeps track of how many tasks are being processed, logging every step. The system processes these tasks in batches (say 5 at a time) to keep everything efficient.

The Vendor Rule comes into picture when the company needs to place larger orders from external suppliers, like those laptops or other big items. The system handles the entire vendor interaction, ensuring that orders are placed with the right suppliers and that everything is tracked properly. Just like the stockroom tasks, the system logs each step here too.

As the system processes the tasks, it logs the progress. For instance, it may say, “5 tasks processed, 10 remaining,” so you always know where the job stands. Once everything is processed, the system marks the job as “completed,” or if anything goes wrong, it logs an error and marks it as “failed.”

So basically this automated process ensures that your company’s inventory is always stocked up without you having to worry about it. It’s like having a robot manager, always keeping your stock in check, whether it’s internal supplies or vendor orders.

 

If my response was helpful, please mark it as correct so it can be valuable to others.

 

Thanks 

Jaishree R

AshishKM
Kilo Patron
Kilo Patron

Hi @anvitha ash

 

Please refer the similar post replied by @Daniel Slocum   

How to configure my stock rule in Hardware Asset M... - ServiceNow Community

 

-Thanks,

AshishKM

 

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

JaishreeR
Giga Guru

Hi @anvitha ash 

 

If my response was helpful, please mark my answer helpful 👍 and accept as a solution  so it can be valuable to others.

 

Thanks 

Jaishree R