rfawcett
Tera Contributor

I found this useful, but it was not documented anywhere.   Hope someone else will find it handy as well.

Contents of MetricInstance Object

definition : [object GlideRecord]//definition GR

current : [object GlideRecord]//currentGR such as task or incident record

initialize :

function (definitionGR, currentGR) {

      this.definition = definitionGR;

      this.current = currentGR;

}

process :

function () {

      answer = true;

      mi = this;

      eval(this.definition.script);

      if (!answer) {

              return;

      }

      this.endDuration();

      this.startDuration();

}

startDuration :

function () {

      var gr = this.getNewRecord();

      gr.field_value = this.current[this.definition.field];

      gr.start = current.sys_updated_on;

      gr.insert();

}

endDuration :

function () {

      var gr = new GlideRecord("metric_instance");

      gr.addQuery("definition", this.definition.sys_id);

      gr.addQuery("id", this.current.sys_id);

      gr.addQuery("calculation_complete", false);

      gr.query();

      if (!gr.next()) {

              return;

      }

      gr.end = this.current.sys_updated_on;

      gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());

      gr.calculation_complete = true;

      gr.update();

}

getNewRecord :

function () {

      var gr = new GlideRecord("metric_instance");

      gr.table = this.current.getRecordClassName();

      gr.id = this.current.sys_id;

      gr.definition = this.definition.sys_id;

      gr.field = this.definition.field;

      return gr;

}

metricExists :

function () {

      var gr = new GlideRecord("metric_instance");

      gr.addQuery("id", this.current.sys_id);

      gr.addQuery("definition", this.definition.sys_id);

      gr.query();

      return gr.hasNext();

}

_z :

function () {

}

Comments
jnovack
Kilo Guru

This is good to note!     Would be wonderful if the Official Developer documentation had this, but I guess maybe NEXT year.



I came here SPECIFICALLY wondering if metricExists() checked for ACTIVE or not.   Turns out it does NOT.   Thanks rfawcett


Version history
Last update:
‎09-18-2017 01:51 PM
Updated by: