Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

BR to check if number of asset is less then threshold value in stockrule

Shweta Maurya
Tera Contributor

Hey

 

Requirement-Need to send notification when number of assets is less then threshold value in stock rule.

 

Issue-how can I fetch number of assets in that particular stockrule.

 

Please suggest

 

Thanks,

Shweta 

 

2 REPLIES 2

Paul Curwen
Giga Sage

Try this: 

 

Create an After Business Rule and Check Update

 

Table:  alm_asset

 

Condition: current.quantity < current.threshold

 

Script as below: 

 

 

// Check if an asset quantity has gone below the threshold
(function executeRule(current, previous /*null when async*/) {

    // Ensure quantity and threshold fields are available
    if (current.quantity < current.threshold) {
       
        // Example: Trigger a notification or alert the relevant team
        gs.addInfoMessage("The asset " + current.name + " has gone below the threshold.");

        // Optionally create an incident or task for restocking
        var incident = new GlideRecord('incident');
        incident.initialize();
        incident.short_description = "Asset " + current.name + " has gone below the threshold";
        incident.description = "The asset quantity for " + current.name + " is " + current.quantity +
                               ", which is below the threshold of " + current.threshold + ".";
        incident.insert();
    }

})(current, previous);

 

 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

Kieran Anson
Kilo Patron

Is this a count of all assets in a stockroom? Because that doesn't make sense. It should be model specific. "Tell me when the number of Lenovo X3 laptops drop below X number"

 

If it's the latter, a stock rule and the 'Stock Rule Runner' scheduled job will do the functionality you're wanting. An asset.restock event is triggered which could be used to trigger a notification