Time duration in metrics

Anandini
Tera Expert

adding a new metrics instance definition type. Use case is a "new" created ticket time spent from the point its new and unassigned to "Assign to."

 

Help show how long tickets sit unmanaged.

2 ACCEPTED SOLUTIONS

Manikanta Kota
Mega Guru

Hi @Anandini ,

 

You can Create SLA for the above mentioned.

Should my answer prove to be helpful, kindly mark it as such by clicking "Accept as Solution" and "Helpful."

 

regards,

Manikanta. Kota

View solution in original post

Aditya02
Tera Guru

Hi @Anandini ,

 

You can follow these steps to get your job done:

 

  1. Navigate to Metrics Definitions:
  2. Go to Metrics > Definitions and click on Create New.
  3. Set Up the Metric Definition:
  • Name: Provide a name for the metric.
  • Table: Select Incident.
  • Field: Choose Assigned to.
  • Type: Select Script Calculation.

 

Script Calculation:  Use the following script to create the metric:

 

var AssignedTo = current.assigned_to;
if (AssignedTo != '')
createMetric();

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

var gr = mi.getNewRecord();
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();
}


This script checks if the Assigned to field is not empty and then creates a metric instance,
calculating the duration from when the incident was created to when it was updated.

 

 

 

===================================***************=========================================

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thanks & Regards,

Aditya

=====================================***********==========================================

 

View solution in original post

7 REPLIES 7

Manikanta Kota
Mega Guru

Hi @Anandini ,

 

You can Create SLA for the above mentioned.

Should my answer prove to be helpful, kindly mark it as such by clicking "Accept as Solution" and "Helpful."

 

regards,

Manikanta. Kota

Aditya02
Tera Guru

Hi @Anandini ,

 

You can follow these steps to get your job done:

 

  1. Navigate to Metrics Definitions:
  2. Go to Metrics > Definitions and click on Create New.
  3. Set Up the Metric Definition:
  • Name: Provide a name for the metric.
  • Table: Select Incident.
  • Field: Choose Assigned to.
  • Type: Select Script Calculation.

 

Script Calculation:  Use the following script to create the metric:

 

var AssignedTo = current.assigned_to;
if (AssignedTo != '')
createMetric();

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

var gr = mi.getNewRecord();
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();
}


This script checks if the Assigned to field is not empty and then creates a metric instance,
calculating the duration from when the incident was created to when it was updated.

 

 

 

===================================***************=========================================

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thanks & Regards,

Aditya

=====================================***********==========================================

 

brahmandlapally
Mega Guru

Hi @Anandini 

Steps to create a metric for 'New to Assigned' in ServiceNow:

  1. Go to the Metric Definitions module
  2. Configure the Metric Definition
  3. Set the Conditions (Start and End Conditions).
  4. Duration Calculation.
  5. Save the Metric Definition:
  6. Test the Metric: