Report on average duration to close a ticket

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 01:18 PM
Hi All,
I am new to reports. I was asked to create a report/graph which shows average time/duration to close a ticket(RITM/SCTASK). Any ideas please?
Thanks,
Karthik.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 01:32 PM
You can configure metric definition on sc_req_item and sc_task to calculate durations for closing tickets.
And then, you can report on metric_instance table.
https://docs.servicenow.com/bundle/london-servicenow-platform/page/administer/assessments/task/t_CreateAMetricDefinition.html
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 03:19 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 08:20 PM
Your new metric definition will create metric instance for only new incidents from now.
If you want metric instance to be created for old incidents, then please run below fix script.
/*jslint eqeq: true, undef: true, sloppy: true, vars: true */
/*global gs, GlideRecord*/
var definition = new GlideRecord('metric_definition');
definition.get(event.parm1);
definition.query();
if (definition.next()) {
var targetRecord = new GlideRecord(definition.table);
targetRecord.orderBy('sys_created_on');
gs.log(definition.name + ': Query against the target table(' + definition.table + '): ' + targetRecord.getEncodedQuery(), 'historic.metric.instances');
targetRecord.addQuery('sys_created_on', '>', definition.u_create_metrics_after);
targetRecord.query();
while (targetRecord.next()) {
var audit = new GlideRecord('sys_audit');
audit.addQuery('documentkey', targetRecord.sys_id.toString());
audit.addQuery('fieldname', definition.field);
audit.orderBy('record_checkpoint');
audit.query();
while (audit.next()) {
try {
var arrOfFields = [];
var count = new GlideAggregate('sys_audit');
count.addQuery('documentkey', targetRecord.sys_id.toString());
count.addQuery('record_checkpoint', audit.record_checkpoint);
count.addAggregate('COUNT', 'fieldname');
count.query();
while (count.next()) {
arrOfFields.push(count.fieldname.toString());
}
arrOfFields = '[' + arrOfFields + ']';
var gdt = new GlideDateTime();
gdt.addSeconds(audit.record_checkpoint * 120);
gs.eventQueueScheduled('metric.update', targetRecord, arrOfFields, audit.record_checkpoint, gdt);
} catch (e) {
gs.log('generateScriptedMetrics against ' + current.number.toString() + ' for ' + definition.name.toString() + 'Error: ' + e, 'historic.metric.instances');
}
}
}
}
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2019 09:12 AM
Hi Sachin,
What is "u_create_metrics_after"? Where and why did you used this for?
Thanks,
Karthik