Schedule a Script to calculate asset depreciation

AndyB5000
Mega Guru

I am working to setup the Asset Management module and came across an issue.  I created a report showing the depreciation details for our assets, however, I the report does not force the depreciated amounts to update depending on the date the report was run.  

I understand that this cannot be done within the report itself, but I am looking for a script that I can setup as a scheduled job to update the depreciation amount on a daily basis automatically so when this report is requested I do not have to manually go to each asset record and click the 'calculate depreciation' button.  

 

I have already tried taking the UI Action script for the calculate deprecation and adding it into a schedule job, but it did not work so I assume I am missing something.  Is this possible?

 

(new DepreciationUtils()).calcDepreciation(current)

1 ACCEPTED SOLUTION

Mark Stanger
Giga Sage

You'll need to query for the assets you need before passing them into the function.  Something like this should work better.

var alm = new GlideRecord('alm_hardware');
alm.query();
while (alm.next()) {
    (new DepreciationUtils()).calcDepreciation(alm)
}

You might also consider adding an 'addQuery' line before the 'alm.query()' line to restrict this somewhat so that it's not running against assets that don't need it, but that's the general idea.

View solution in original post

2 REPLIES 2

Mark Stanger
Giga Sage

You'll need to query for the assets you need before passing them into the function.  Something like this should work better.

var alm = new GlideRecord('alm_hardware');
alm.query();
while (alm.next()) {
    (new DepreciationUtils()).calcDepreciation(alm)
}

You might also consider adding an 'addQuery' line before the 'alm.query()' line to restrict this somewhat so that it's not running against assets that don't need it, but that's the general idea.

26stabassum
Tera Contributor

It is not working for me as well. @AndyB5000  did it work for you ?