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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @swapnil15 

 

Did you try the SLA. It will be same.

 

LearnNGrowAtul_0-1702895925960.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG ,
I have an issue with the report. If the end user changes the assigned to multiple times, it will keep on updating the user. I only need the first assignee .

Hi @swapnil15 

 

Thanks for clarification. In this case you need to do metrics Script only and @Saurabh Gupta   already suggested the same.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

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