Asset Quantity Field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 01:50 AM
I have got this script that should do the following-
Take the quantity field - asset tasks associated = stock remaining,
Does not currently working, is there any advise/suggestions on this
------------------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 02:49 AM
Where are you using this logic?
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 02:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 02:53 AM
is this an after update business rule? on which table? share some screenshots
Did that business rule trigger?
try this
function onAfter(current, previous) {
// Replace 'asset' with your actual reference field name if different
if (current.asset.nil()) {
gs.info("Asset reference is missing.");
return;
}
var assetGR = new GlideRecord("alm_asset"); // Use your actual asset table
if (assetGR.get(current.asset.toString())) {
var remaining = parseInt(assetGR.getValue("u_stock_remaining"), 10) || 0;
var qty = parseInt(current.quantity, 10) || 1; // Default to 1 if quantity not set
// Only decrement if enough stock remains
if (remaining >= qty) {
assetGR.setValue("u_stock_remaining", remaining - qty);
assetGR.update();
gs.info("Asset stock decremented by " + qty + ". New value: " + (remaining - qty));
} else {
gs.info("Not enough stock to decrement. Current: " + remaining + ", Requested: " + qty);
}
} else {
gs.info("Failed to find asset record for sys_id: " + current.asset);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 02:58 AM