How to I recalculate availability for all Service Offerings / Service Commitments for the past year?

brianmelvin
Tera Contributor

Currently there is an out of the box scheduled job that runs every morning at 2:00 AM that recalculates availability for the past day. We've recently made some changes to the schedules that are utilized by our Service Commitments, and need to recalculate availability for all Service Offerings.  

The 'Calculate Availability' scheduled job passes a start value as an argument to the script include AvailabilitySummarizer. (below)

var ac = new AvailabilitySummarizer();   var start = new GlideDateTime();   start.setValue(gs.beginningOfYesterday());   ac.summarize(start);

Initially I thought we may be able to simply swap out the third line with  start.setValue(gs.beginningOfLastYear());, however it looks as if the AvailabilitySummarizer will only calculate until the end of the day it starts on.  

There is a UI action 'Calculate Past Availability' on the Service Offering table that calculates all availability for the past 400 days for the CI of that Service Offering.  

current.update(); action.setRedirectURL(current);   var oldTZ = gs.getSession().getTimeZoneName(); var defaultTZ = GlideUser.getSysTimeZone(); gs.print("Setting session timezone to " + defaultTZ + " for Service Offering availability calculations"); gs.getSession().setTimeZoneName(defaultTZ);   recalcAvailability();   gs.getSession().setTimeZoneName(oldTZ); gs.print("Restored session timezone to " + oldTZ + " after Service Offering availability calculations");   function recalcAvailability() {       var current_ci_class = current.cmdb_ci.sys_class_name;       var newBeginVal = new GlideDateTime().getNumericValue();       var d = new GlideDateTime();       d.addDays(-400)       newEndVal = d.getNumericValue();       updateCalc(newBeginVal, newEndVal); }   function updateCalc(v1, v2) {       if (v1 == v2 || v1 == 0 || v2 == 0)             return;         var today = new GlideDateTime(gs.beginningOfTomorrow()).getNumericValue();       low = Math.min(v1, v2);       high = Math.max(v1, v2);       gs.print("Calculating past year availability for Service Offering: " + current.getDisplayValue());       while (low <= high && low < today) {             var d = new GlideDateTime();             d.setNumericValue(low);             var ac = new AvailabilitySummarizer();             ac.setCI(current.sys_id);             ac.summarize(d);               low += 24 * 3600 * 1000;       } }

Is it possible to accomplish this by simply running this without specifying a CI (instantiating the AvailabilitySummarizer class with a null CI)?  

1 REPLY 1

Shane J
Tera Guru

Brian - I know this was 2 yrs ago but I have the same question but was looking at an alternate solution (fixing the BR: 'Recalculated Availability').

 

Do you know what you ended up doing here?