Community Alums
Not applicable
Options
- 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.