- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 01-10-2020 05:40 AM
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 changes
createMetric();
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 exists
createNewMetric();
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
- 783 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks, I had exactly the same requirement and this script worked perfectly !!