Is there a function to bulk calculate depreciation?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 07:08 PM
I need to update a few hundred records in ServiceNow and for the system to start calculating depreciation for these records. The only way that I understood how to do it is to click on the 'Calculate depreciation' macro on the Depreciation tab of the Hardware Asset record. Is there a way to do it in bulk instead of clicking one by one?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 07:43 PM
All that link at the bottom does is
new DepreciationUtils()).calcDepreciation(current)
Theoretically, if you create a script that queries the assets you want to depreciate, then pass them through instead of 'current', that could work. This could be run as a fix script or a scheduled job or in another Action you have to click for 'calculate all'.
Disclaimer: this code was not tested, has no error handling, and can affect many records. Always test in a subprod.
var assets = new GlideRecord("alm_hardware");
assets.addQuery() // Query here
assets.query();
var depreciationUtil = new DepreciationUtils(); // salvage what little efficiency we can
while(assets.next()){
depreciationUtil.calcDepreciation(assets)
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 07:47 PM
Hi @Jerry Ong ,
depreciation will calculate when record updated with dep start date and allocate to user but you can trigger it from schedule job or if you need one time then use fix script or background script
var assetGR = new GlideRecord('alm_hardware');
assetGR.addQuery('your_conditions_here'); // Add conditions if needed (e.g., only assets that haven't had depreciation calculated)
assetGR.query();
while (assetGR.next()) {
assetGR.calculateDepreciation(); // Trigger depreciation calculation
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 11:14 PM
Thank you Runjay, I supposed that is the way it should work too but the figures aren't updating after a day so I am monitoring it now.