Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

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 

 

In my PDI it is working as expected-

SaurabhGupta_0-1702914613393.png

Below is the part of code, which will make sure it will run only on first assignment.

var mi = new MetricInstance(definition, current);
  if (mi.metricExists()) 
    return;

Thanks and Regards,

Saurabh Gupta

Hi @Saurabh Gupta  ,

Apology, I have kept the type as field value duration hence the issue.

It works well as expected now, thanks a million.