Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

service outage metrics calculation not working on the incident

Vinod S Patil
Tera Contributor

Hello Everyone

Need your suggestion, when incident moved to high priority its creating the service outage metrics but time/duration bot being updated. please have look at below screen shot.


VinodSPatil_0-1762421343303.png



@Ankur Bawiskar 

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Vinod S Patil 

Is the group getting created automatically, or is there a manual process involved?
As far as I know, it’s a manual process.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Ankur Bawiskar
Tera Patron
Tera Patron

@Vinod S Patil 

did you identify how that Outage metrics record is created?

may be the script doesn't have logic to set those fields?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Vinod S Patil
Tera Contributor

@Ankur Bawiskar  @Dr Atul G- LNG 

Below after BR being used to update those details but its not working

  var logger = new global.GSLog('org.kp.itss.incident.metric.utils.log', 'KP:I00110');
    var duration = '';
    var proposedOn;
    var somc = null;
    var metricGR = null;
    var ciOutageGR = null;
    var serviceOutageMetricsGR = null;
    var newServiceOutageMetricsGR = null;
    var metricDefSysId = gs.getProperty('org.kp.itss.incident.metric.major_inc_state_dur.sys_id');

    logger.logDebug('executing');

    try {

        if (logger.debugOn()) {
            logger.logDebug('current.sys_id = ' + current.sys_id);
            logger.logDebug('current.number = ' + current.number);
        }

        somc = new global.KPServiceOutageMetricCalc();

        metricGR = new GlideRecord('incident_metric');
        metricGR.addQuery('mi_definition', metricDefSysId);
        metricGR.addQuery('mi_value', 'Proposed');
        metricGR.addQuery('inc_number', current.number);
        metricGR.orderBy('mi_start');
        metricGR.query();

        if (metricGR.next()) {
            proposedOn = metricGR.mi_start.dateNumericValue();
        }

        if (current.resolved_at != previous.resolved_at && (current.state == 6 || current.state == 7)) {

            ciOutageGR = new GlideRecord('cmdb_ci_outage');
            ciOutageGR.addQuery('task_number', current.sys_id);
            ciOutageGR.addQuery('u_state', 'IN', [1, 2, 3, 4]);
            ciOutageGR.addQuery('type', 'outage');
            ciOutageGR.query();

            if (ciOutageGR.hasNext() == false) {

                serviceOutageMetricsGR = new GlideRecord('u_service_outage_metrics');
                serviceOutageMetricsGR.addQuery('u_task', current.sys_id);
                serviceOutageMetricsGR.query();

                if (serviceOutageMetricsGR.next()) {

                    serviceOutageMetricsGR.u_total_outage_time = gs.dateDiff(current.sys_created_on.getDisplayValue(), current.resolved_at.getDisplayValue(), false);
                    serviceOutageMetricsGR.u_business_disruption_outage_hours = gs.dateDiff(current.sys_created_on.getDisplayValue(), current.resolved_at.getDisplayValue(), false);
                    serviceOutageMetricsGR.u_created_to_latest_outage_end = gs.dateDiff(current.sys_created_on.getDisplayValue(), current.resolved_at.getDisplayValue(), false);
                    serviceOutageMetricsGR.update();

                } else {

                    newServiceOutageMetricsGR = new GlideRecord('u_service_outage_metrics');
                    newServiceOutageMetricsGR.u_task = current.sys_id;
                    newServiceOutageMetricsGR.u_total_outage_time = gs.dateDiff(current.sys_created_on.getDisplayValue(), current.resolved_at.getDisplayValue(), false);
                    newServiceOutageMetricsGR.u_business_disruption_outage_hours = gs.dateDiff(current.sys_created_on.getDisplayValue(), current.resolved_at.getDisplayValue(), false);
                    newServiceOutageMetricsGR.u_created_to_latest_outage_end = gs.dateDiff(current.sys_created_on.getDisplayValue(), current.resolved_at.getDisplayValue(), false);
                    newServiceOutageMetricsGR.insert();

                }

            } else {
                somc.recalcMetricOutage(current.sys_id, duration, current.sys_created_on.dateNumericValue(), proposedOn, current.resolved_at.dateNumericValue(), current.state);
            }

        }

        if (current.resolved_at == '' && current.state < 6) {
            somc.recalcMetricOutage(current.sys_id, duration, current.sys_created_on.dateNumericValue(), proposedOn);
        }

    } catch (err) {
        logger.logErr('exception encountered, err=' + err);
    }

})(current, previous);

@Vinod S Patil 

so what debugging did you do? added logs?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader