Incident Metrics - Metric Instance Scripting

Subhajit1
Giga Guru

Incident Metrics - Require a Metric Instance to calculate the duration of a ticket assigned to a particular group irrespective of how many times the ticket was reassigned to the group. The instance should measure the total time duration the ticket was assigned to a particular Assignment Group, irrespective of how many times it got assigned to other groups.

 

Regards,

Subhajit

4 REPLIES 4

Bhavesh Jain1
Giga Guru

To start with, yes you need to do script value calculation. Now whenever a ticket gets assigned to a group, perform a check in metric_instance table to see if there is already a value for the same incident and assignment group. If yes, set the start time to the current.sys_update_on. Now when this ticket gets assigned a new group, query for old assignment group in metric instance table and update the end time. And update the new duration as per the old duration.


something like : duration = duration + (endtime - start time);
Yes it is bit complex but thats the way I could think of. I would have written the script but it started taking some time so thought of sharing the idea.


davejr
Giga Contributor

I created a metric, called "Assignment Group to Resolved"


table: incident


field: assignment group


type field value duration



then a business rule:


stop Assgmt Gp Metric if resolved


before, update, condition: incident state is resolved



answer=false;


findDurations();



function findDurations() {


      var gr = new GlideRecord('metric_instance');


      gr.addQuery('id', current.sys_id);


      gr.addQuery('definition.name','Assignment Group to Resolved');


      gr.query();


      while(gr.next()){


              var def = new GlideRecord('metric_definition');


              def.get(gr.definition.name);


              var mi = new MetricInstance(def, current);


              mi.endDuration();


      }


}




It gives me the metric showing the duration of the ticket with a group that stops when it is resolved.


We leave an Incident resolved for 5 business days before the system closes it.


The OOB metric does not stop until it is closed.


If I re-assign to another group, the OOB metric is stopped.


It all should be on oncident table or incident metric?especially reporting part


Referring to David Richter's solution:



You'll build a new metric in the metric definition table (or insert and stay on the existing "Assignment Group" metric)



Then build the business rule on the Incident table.   If you open a new tab and look at the metric_instance.list while you create a new instance (with an assignment group), give it a few minutes, then resolve and close it, you can see how the metric_instance table works.



Basically all you're doing is opening a new GlideRecord query to that metric instance table, filtering for the queries you want to stop, and then feeding them into that "endDuration" command.   I've never seen someone do a single argument get by name though, usually unless you specify which field to look in, Get assumes a single argument to be a sys_id, so I'd be tempted to adjust the code to def.get(gr.definition);