Metrics : On resolve state after reopen the incident.

Nageshwari P
Tera Contributor

Hi Team,
I have a requirement that, when the incident ticket is resolved then the metric "create to set resolved duration " is calculated and the resolved time on incident and the metric end time is matching.
But, when the incident ticket is reopened and resolved it again then the actual resolved time in Incident ticket and the end time in metric is not matching.
Can I know how to resume the metric and calculate the actual resolved time after reopen and resolved, and the end time in metrics do match?

Thanks and Best Regards,
Nageshwari P.

1 ACCEPTED SOLUTION

Hello @Nageshwari P 

 

Those are just comments you can set it to backend values of resolved. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

View solution in original post

9 REPLIES 9

Shivalika
Mega Sage

Hello @Nageshwari P 

 

Please share this metric definition screenshot and script. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Hi @Shivalika,

 

Please find the attached screenshots.

 

Thanks & regards,
Nageshwari P

Hello @Nageshwari P 

 

Please use below 👇 modified script - 

 

var s = current.incident_state;

// If the incident is resolved or closed, create or update the incident metric
if (s >= 6) { 
    createOrUpdateIncidentMetric();
}

function createOrUpdateIncidentMetric() {
    var gr = new GlideRecord('incident_metric');
    gr.addQuery('incident', current.sys_id);
    gr.addQuery('metric_type', 'create_to_resolved'); // Ensure this metric type exists
    gr.orderByDesc('sys_created_on'); // Get the latest metric record
    gr.query();

    if (gr.next()) {
        if (current.state == 6) { // If resolved again, update the metric
            gr.end_time = current.sys_updated_on;
            gr.calculation_complete = true;
            var sched = new GlideSchedule('ba7530901bcf2450988887f7cc4bcb8b'); 
            gr.duration = sched.duration(gr.start_time.getGlideObject(), gr.end_time.getGlideObject());
            gr.update();
        }
        return;
    }

    // Create a new metric record if one does not exist
    var newGr = new GlideRecord('incident_metric');
    newGr.incident = current.sys_id;
    newGr.metric_type = 'create_to_resolved'; // Ensure the metric type is configured
    newGr.start_time = current.sys_created_on;
    newGr.end_time = current.sys_updated_on;
    
    var sched = new GlideSchedule('ba7530901bcf2450988887f7cc4bcb8b'); 
    newGr.duration = sched.duration(newGr.start_time.getGlideObject(), newGr.end_time.getGlideObject());
    
    newGr.calculation_complete = true;
    newGr.insert();
}

 

 

Lme know if you face any errors. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Hi @Shivalika ,
After the modification of script, Metric definition is not getting assigned to the Incident.
Best Regards,
Nageshwari P.