Metric Definition to Calculate first assignee

swapnil15
Tera Contributor

Hi All,

I have a task to get the time between - when the ticket was created and the first assignee. I have created metrics for the same. I need help with the script which will exclude all the other assignees except the first and show me the time in metric definition.

1 ACCEPTED SOLUTION

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,

// variables available
// current: GlideRecord -  target incident
// definition: GlideRecord -  (this row)
if (current.assigned_to) {
  
      value = current.assigned_to;
     
  createMetric(value);
}

function createMetric(value) {
  var mi = new MetricInstance(definition, current);
  if (mi.metricExists()) 
    return;

  var gr = mi.getNewRecord();
  gr.field_value = value;
  gr.field = "assigned_to";
  gr.start = current.sys_created_on;
  gr.end = current.sys_updated_on;
  gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
  gr.calculation_complete = true;
  gr.insert();
}


 


Thanks and Regards,

Saurabh Gupta

View solution in original post

11 REPLIES 11

Hi @swapnil15 



Thanks and Regards,

Saurabh Gupta

Thanks for the script @Saurabh Gupta  .
If a user changes the assignee to a blank/ empty and again assigns a user the script will give the wrong time. How to control this?

Hi @swapnil15 
It will only create one record in metric instance.



Thanks and Regards,

Saurabh Gupta

hi @Saurabh Gupta  ,
I tried making changes to the assigned_to multiple times, and multiple records were recorded in the metrics for the above script. PFA

Hi,
Share the metric definition record please?


Thanks and Regards,

Saurabh Gupta