Set the value of the metric duration field to the field created in the Defects table

Miguel1
Tera Contributor

Hi Experts!!
I made a Metric definition, Type: Script calculation, in Defect [u_defect] table.

This script monitors the status change of the defect from when it is opened until it goes to Inspection. The code works fine but I would like to know how I can take the duration value that the metric does and put it in another duration field inside the defect table.

Any ideas please?

add Image and link below:

find_real_file.png

find_real_file.png

var s = current.state;
if (s == 2) //2 == Inspection
  createMetric();

function createMetric() {
  var mi = new MetricInstance(definition, current);
  if (mi.metricExists()) 
    return; 

  var gr = mi.getNewRecord();
  gr.start = current.opened_at;
  gr.end = current.sys_updated_on;
  gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
  gr.calculation_complete = true;
  gr.insert();
}