Want to create a MTTR Response incident report

MayurChaudhari
Tera Contributor

I Want to create a MTTR Response incident report from 'Created to Assigned to'. Need to calculate time duration from Incident created to gets assigned to someone. 

 

This is Metric Definition for 'Create to Resolve Duration'

MayurChaudhari_0-1724671472941.png

 

Code - 

 

// variables available
// current: GlideRecord -  target incident
// definition: GlideRecord -  (this row)
var s = current.incident_state;
if (s >= 6)
  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();
}
 
- What changes I have to make in it to create a Metric Definition for 'Create to Assigned to'.
Please guide me on this.

 

6 REPLIES 6

Sorry my friend, I am not a developer so scripting is not my area.

 

@Sandeep Rajput  @Community Alums @Mark Manders can you help here.

*************************************************************************************************************
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]

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

Just don't. Use the SLA's for this. They want to report on this, so create a report on the task_sla table. You are there to provide them with the best possible solution. Metrics can have huge performance implications. 

 

You need to provide your clients with this information, because 'this is what we already have/did' does not make it the best solution. Please let the SLA engine take care of this requirement. 

 

Your metric script would look like this, but just don't use it.

var previousAssignedTo = current.getPreviousValue('assigned_to');  // Get the previous value of assigned_to
var currentAssignedTo = current.getValue('assigned_to'); 
if (!previousAssignedTo && currentAssignedTo) {
	createMetric();
}

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

	var newRecord = metricInstance.getNewRecord();
	newRecord.setValue('start', current.getValue('sys_created_on'));
	newRecord.setValue('end', current.getValue('sys_updated_on'));
	newRecord.setValue('duration', gs.dateDiff(newRecord.getDisplayValue('start'), newRecord.getDisplayValue('end')));
	newRecord.setValue('calculation_complete', true);
	newRecord.insert();
}

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark