Report on average duration to close a ticket

karthikbabu
Giga Expert

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.

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

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

Hi Sachin,

 

I created below metric definition.

find_real_file.png

when I try to run a report on "Metric instance" table I am seeing 0 records

find_real_file.png

Did I do any thing wrong in these steps?

 

Thanks,

Karthik.

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

Hi Sachin,

 

What is "u_create_metrics_after"? Where and why did you used this for?

 

Thanks,

Karthik