
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2021 05:21 AM
One of our clients needs to have a report created that would show them the time taken to complete an INC after it was assigned to an ITIL User. Their SLA Definitions for resolution calculate the entire lifecycle of the INC from the time it was opened until closed. I came across the Metrics table and found the below Metric for INC which calculate the duration from Open to Resolved/Closed.
Hoping to build a similar metric that would allow me to calculate duration from first assigned to until Resolved/Closed. Any help or suggestions would be much appreciated. Thank you.
Solved! Go to Solution.
- Labels:
-
Service Level Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2021 02:50 AM
Hello
So what I suggest to you is to create a field type Date/Time to store type when the field changes for the first time :
To get the time when assigned to changes for the first time you have to create a before business rule as shown bellow :
(function executeRule(current, previous /*null when async*/ ) {
if (gs.nil(previous.assigned_to) && current.assigned_to) {
var date_assigned_to = new GlideDateTime(gs.nowDateTime());
current.u_assigned_to_changes_on = date_assigned_to;
}
})(current, previous);
Results after assign incident to a user :
The last step is to create a metric and start calculating :
// current: GlideRecord - target incident
/*if (current.assigned_to) {
createMetricAssignedTo();
}*/
var state = current.state;
if(state>=6){
createMetric();
}
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.start = current.u_assigned_to_changes_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.calculation_complete = true;
gr.insert();
}
Results :
Closed incident :
I hope that what you are looking for.
Best regards.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2021 08:18 AM
Instead of script, try using Field Duration.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2021 10:13 AM
I am also interested more on using the GUI rather than scripts.
Do you have any idea, how this can be done?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2021 02:50 AM
Hello
So what I suggest to you is to create a field type Date/Time to store type when the field changes for the first time :
To get the time when assigned to changes for the first time you have to create a before business rule as shown bellow :
(function executeRule(current, previous /*null when async*/ ) {
if (gs.nil(previous.assigned_to) && current.assigned_to) {
var date_assigned_to = new GlideDateTime(gs.nowDateTime());
current.u_assigned_to_changes_on = date_assigned_to;
}
})(current, previous);
Results after assign incident to a user :
The last step is to create a metric and start calculating :
// current: GlideRecord - target incident
/*if (current.assigned_to) {
createMetricAssignedTo();
}*/
var state = current.state;
if(state>=6){
createMetric();
}
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.start = current.u_assigned_to_changes_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.calculation_complete = true;
gr.insert();
}
Results :
Closed incident :
I hope that what you are looking for.
Best regards.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2021 12:18 PM
I used gr.end = current.closed_at; instead of the updated_on field.
Works !
Thank you