Help With 'Time Until Assigned' Metric

Kevin Ng
Tera Expert

My company would like to start reporting on the time it takes (duration) when a ticket is assigned to a group and when it's actually assigned to an individual. I found a post from someone with similar requirements and have modified their metric to closer meet my company's needs...

if (current.assigned_to != '')


  {


  var value = false;


  if (!current.active)


  value = true;



  createMetrice(value);



}




function createMetrice(value) {

  var gr = mi.getNewRecord();


  gr.field_value = value;


  gr.start = current.sys_updated_on;


  gr.end = gs.nowDateTime();


  gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());


  gr.calculation_complete = true;


  gr.insert();


}

The problem that I'm having is that in situations where an incident is assigned to multiple groups, I'm unable to filter which assignment group is associated with the metric instance. 

Is there any way I can capture the current assignment group at the time of the metric instance creation?

Thank you!

Kevin

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

This'll need two metrics, one to record assignment group "touches" and one to do the secondary logic.

 

1. Create a simple assignment group field value duration metric

find_real_file.png

 

2. Create a second metric with the below script.

find_real_file.png

This script checks to find if an assignment metric exists (it should) and returns the time the metric was created. It then creates a metric with the duration calculated on the difference of the assignment group metric start time and the current time.

var mi = new MetricInstance(definition,current);
var start = groupMetric();

if(start != null && !mi.metricExists()){
	var gr = mi.getNewRecord();
	gr.start = start;
	var now = new GlideDateTime();
	gr.end = now;
	gr.duration = gs.dateDiff(start, now);
	gr.value = current.getDisplayValue('assigned_to');
	gr.calculation_complete = true;
	gr.insert();
}


function groupMetric(){
	var metricGR = new GlideRecord('metric_instance');
	metricGR.addQuery("definition","06f9db6d2f94a8101c43bed72799b6c2"); //sys_id of assignment group touch metric (store in sys property);
	metricGR.addQuery("id",current.sys_id);
	metricGR.addQuery("value",current.getDisplayValue("assignment_group"));
	metricGR.query();
	metricGR.next();
	return metricGR.start;
}

 

 

Result: We can see the incident was assigned to ACME Support at 21:42:35 and then an assignee allocated at 21:43:15. This shows a 40 second window between the assignment group being set and then actually being assigned to a user to fulfill.

find_real_file.png

 

View solution in original post

14 REPLIES 14

Hey Kieran, 

 

I found this really useful for a requirement i've received many thanks! 

Quick question is there any way i can drill this search result down using the short description?

Trying to use indexof to try and show only tickets with short descriptions using a specific word but so far seems to just ignore it...

this is the amended code 

var mi = new MetricInstance(definition,current);
var start = groupMetric();
var d = current.getDisplayValue("short_description");

if(start != null && !mi.metricExists() && d.indexOf('Phish') >=0){ 

 

any ideas? 

Thank you 

Hiya Sam,

Are you only wanting a metric created if the description contains "phish" in some place?

If so, the following should work? (I think, I've not tested):

var mi = new MetricInstance(definition,current);
var start = groupMetric();
var d = current.getValue("short_description");

if(start != null && !mi.metricExists() && d.indexOf('Phish') > -1){ 

Hi Kieran, 

Thanks for getting back to me really appreciate the response. 

I actually ended up using your method to create the 2 metrics and then created a report on Time Until Assigned as the definition where i could then filter the results 

thanks again super useful stuff!

Kevin Ng
Tera Expert

Hey Kieran,

It's set to the 'Assigned to' field...

 

find_real_file.png

You can see when I enable the column in the report for Duration (mi_duration) that I still get the duration as well as the assignment group.

find_real_file.png

The durations appear to be correct. I only waited a few seconds between each assigned_to change. The very bottom one was me assigning a ticket directly to a person within that assignment group so the duration is 0. 

Kevin

Ashley Snyder1
Giga Guru

@Kieran Anson I'm trying this out and noticed if I assign an Incident to one group, and then add the assigned to, it will capture that first instance, but if I re-assign to another group and another assigned to, the second instance isn't captured.  Am I missing something with this?