Not applicable

Hello @Manan ,

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 : 

find_real_file.png

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 : 

find_real_file.png

 

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 :

find_real_file.png

 

 

find_real_file.png

 I hope that what you are looking for. 

Best regards.

View solution in original post