How to calculate metrics time from start to till closure on HR Case

yashu1995
Kilo Guru

How to calculate metrics time from start to till closure on HR Case.

We need to calculate the Average Time to Close for our HRCs, and this should be based on the duration the case is in the state from creation of case to till closure of case

1 ACCEPTED SOLUTION

dave_edgar
Mega Guru

so you should be able to create a metric on active.  Similar to this:

find_real_file.png

 

Or you can use some coding like this:

define your variables from the table here

createMetric();

}

}
function createMetric() {
var mi = new MetricInstance(definition, current);
var gr = mi.getNewRecord();
gr.start = current.sys_updated_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), createMetric();
}
else{
//gs.log('User is NOT the task caller: ' + calleris + ' . Updater is: ' + updater);
}
function createMetric() {
var mi = new MetricInstance(definition, current);
var gr = mi.getNewRecord();
gr.start = current.sys_updated_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.value = callername;
gr.field_value = null;
gr.calculation_complete = true;
gr.insert();
// gs.log('Caller Metric for definition MTRC0010048 created.');
}.end.getDisplayValue());
gr.value = callername;
gr.field_value = null;
gr.calculation_complete = true;
gr.insert();
}

 

 

Hope that helps, if so please mark as correct or helpful

View solution in original post

4 REPLIES 4

dave_edgar
Mega Guru

so you should be able to create a metric on active.  Similar to this:

find_real_file.png

 

Or you can use some coding like this:

define your variables from the table here

createMetric();

}

}
function createMetric() {
var mi = new MetricInstance(definition, current);
var gr = mi.getNewRecord();
gr.start = current.sys_updated_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), createMetric();
}
else{
//gs.log('User is NOT the task caller: ' + calleris + ' . Updater is: ' + updater);
}
function createMetric() {
var mi = new MetricInstance(definition, current);
var gr = mi.getNewRecord();
gr.start = current.sys_updated_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.value = callername;
gr.field_value = null;
gr.calculation_complete = true;
gr.insert();
// gs.log('Caller Metric for definition MTRC0010048 created.');
}.end.getDisplayValue());
gr.value = callername;
gr.field_value = null;
gr.calculation_complete = true;
gr.insert();
}

 

 

Hope that helps, if so please mark as correct or helpful

I hope this help, please mark as correct if so

 

Dave

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

As @dave_edgar mentions, Metrics is the best out of the box way to solve this and there are several out of the box metric definitions to review.  There is a "Assignment Group Duration for HR Case" metric for the HR Case (sn_hr_core_case) table provided but again you can look at the others for incident and other tables as example.  As mentioned in the linked article above you can create a database view for your reporting needs.

This said I did want to point out a gotcha with metrics.  The way to see metrics associated to a record is via a related list called Metrics.  If you have multiple metric definitions setup this related list allows you to see all the metric instances associated to the record itself.  The Metrics related list is a "defined related list" that has a condition to only show IF there is a metric definition associated to the table.  I mention this because if you attempt to add the metrics related list to your case form you may not see it in the slushbucket because of this restriction.  So for example if you pull up the Payroll COE case form and attempt to add the out of the box Assignment Group Duration for HR Cases, it won't show since that metric definition is associated to the parent core case table and not specifically to the Payroll COE table.

To fix this issue you can modify the out of the box Metrics relationship:

https://INSTANCENAME.service-now.com/nav_to.do?uri=sys_relationship.do?sys_id=412b7b420a258102002a5fdbfab70593

and modify the Apply to Script to the following as it will get the table hierarchy - payroll extends sn_hr_core_case which extends task:

var gr = new GlideRecord('metric_definition');
gr.addQuery('table', 'IN', new global.TableUtils(table_name).getTables());
gr.addActiveQuery();
gr.query(); 
answer = gr.hasNext();

VShine
Mega Guru

I created few metrics for HR case tables. Metrics instances working as expected. But instance staying open even when cast state is close complete. I want Metric instance to stop when case is close complete. My metric definition is on Assigned to , even OOB one  (assignment group for HR case) is having same behavior. I try using script for Incident "Open" metric definition. But its not working for HR case.Here is my Metric Definition.

Can someone help me please!

find_real_file.png