Metric Definition Issue

Cirrus
Kilo Sage

Afternoon,

I have a created a metric definition where Field is Status and Type is Script Calculation. Status 5 = Ready, and I want to measure the duration from the time at which the ticket was created to the time it reaches State = 5. The problem I am having is that every time I create a new ticket (Draft = 1) it triggers the metric and returns a duration of 0. Logging confirms the value of stat = 1. Can anyone advise what's wrong please

 

var stat = current.status;
if (stat = 5)
  createMetric();

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

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

Cirrus
Kilo Sage

 I ended up using 

var stat = current.getValue("status");

if (stat == "5")

    createMetric();

View solution in original post

5 REPLIES 5

Cirrus
Kilo Sage

 I ended up using 

var stat = current.getValue("status");

if (stat == "5")

    createMetric();