logo

NJP

Metric to show Max Priority throughout an incidents lifecycle

Import · Jan 10, 2020 · article

I looked around but could find an answer to this scenario so here was my solution.

I was asked to show throughout the lifecycle of an incident what it's maximum priority was and only have a single metric for the incident for simple reporting.

So here is my metric script:

//custom script to track priority changescreateMetric();function createMetric() {//find any exsisiting metric and compare the priorities var gr1 = new GlideRecord('metric_instance'); gr1.addQuery('id', current.sys_id); gr1.addQuery('definition', 'aa41a7731b8580101072646fad4bcb83'); // =Priority highest used gr1.query(); while(gr1.next() ){ //update any existing metric IF priority higher if (gr1.value > current.priority.getValue()){//gs.log('Higher Priority found, gr1 value == ' + gr1.value + ' - new is = ' + current.priority.getValue()); gr1.end = current.sys_updated_on; gr1.duration = gs.dateDiff(gr1.start.getDisplayValue(), gr1.end.getDisplayValue()); gr1.value = current.priority.getValue(); gr1.update(); }}//creating new metric for Priority as non existscreateNewMetric(); function createNewMetric() { var mi = new MetricInstance(definition, current); if (mi.metricExists()) return;//nothing found so creating new var gr = mi.getNewRecord(); gr.start = current.sys_updated_on; gr.value = current.priority; //Set value to current priority gr.calculation_complete = false; gr.insert(); }

}

// function createNewMetric(){// var mi = new MetricInstance(definition, current);// var gr = mi.getNewRecord();// gr.start = current.sys_updated_on;// gr.value = current.priority; //Set value to current priority// gr.calculation_complete = false;// gr.insert();// }

// }

Hope this helps someone else out

image

View original source

https://www.servicenow.com/community/developer-articles/metric-to-show-max-priority-throughout-an-incidents-lifecycle/ta-p/2311175