We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Metric definition script issue

zheil
Mega Expert

Hi

 

I have an issue with my metric definition script.

 

The metric does not work and I'm not sure if I used the not null condition check correctly, or something else is wrong. Even if a try null, 'NULL', or "NULL" it does not work.

 

I would like the metric to fire when the u_root_cause_ci field is populated for the first time.

 

Can anyone help?

 

if(current.u_root_cause_ci != 'NULL'){

createMatricx(current);  

}  

function createMatricx(current) {

  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.duration = gs.dateDiff(gr.start, gr.end);

  gr.calculation_complete = true;

  gr.insert();

}

1 ACCEPTED SOLUTION

marcguy
ServiceNow Employee

yes, sounds like it try printing what it sees as a value right at the start..



gs.log(current.u_root_cause_ci);


View solution in original post

6 REPLIES 6

marcguy
ServiceNow Employee

yes, sounds like it try printing what it sees as a value right at the start..



gs.log(current.u_root_cause_ci);


Thanks for your help, I found the issue, it's user error on my side... when I created this metric from an existing using insert I did not update the 'Field' value, so you are right that's why the value was not in the log.