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

Hello @Nageshwari P 

 

Ohh , I think I have updated the creation part also of the script thats the reason. Please keep creation part same. 

 

Please use below 👇 script - (Make sure to change the reopened value to your backend values and also what do you want to do with end date ? - you can change that's also per your requirement) 

 

var mi = new MetricInstance(definition, current);

// If metric already exists, check for state before returning
if (mi.metricExists()) {
var existingMetric = mi.getInstanceRecord();

if (current.incident_state == 18) { // 18 = Reopened
existingMetric.calculation_complete = false; // Pause metric
existingMetric.end = null; // Clear end date
existingMetric.update();
}

return;
}

// Create a new metric instance if it doesn't exist
var gr = mi.getNewRecord();

gr.start = current.sys_created_on;
gr.end = current.sys_updated_on;

var sched = new GlideSchedule('ba7530901bcf2450988887f7cc4bcb8b');
var dur = sched.duration(gr.start.getGlideObject(), gr.end.getGlideObject());

gr.duration = dur;
gr.value = current.incident_state.getDisplayValue();
gr.calculation_complete = true;

gr.insert();

There is no such state called reopened in the incident table.

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

Hello @Nageshwari P 

 

Thanks for accepting my solution. I am glad it helped you out. I would recommend, please accept solution for the exact script which I have shared. So, that any future readers refer this, they know which solution is working. 

 

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

Nageshwari P
Tera Contributor

I have created a business rule to populate the Metric whenever we reopen and resolve the ticket. It is working as expected but the duration field is not getting updated.
Whenever I am using the commented script, the metric is not getting assigned. Can you please help me the resolve this issue.

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

// check if it was reopened before resolving

if (current.reopen_count > 0) {

var metric = new GlideRecord('metric_instance');

metric.initialize();

metric.name = 'Create to Resolve Duration';

metric.definition = '35edf981c0a808ae009895af7c843ace'; //metric definition sys_id

metric.id = current.sys_id;

var now = new GlideDateTime();

metric.start = current.sys_created_on;

metric.end = now;

//var sched new GlideSchedule('ba7530901bcf2450988887f7cc4bcb8b');

//var dur = sched.duration(metric.start,metric.end);

//metric.duration dur.getDurationValue();

metric.value = current.incident_state.getDisplayValue();

metric.calculation_complete = true;

metric.insert();

gs.info("Duration Set:" + metric.duration + "| Inserted: " + metric.sys_id);

gs.info("Metric created for " + current.number + " after reopen.");

}