Help with metric script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2017 04:21 AM
Hi,
I have a metric script that should calculate the duration from a change is created and to it's in the state: proposed, sub_state: awaiting_customer_proposal, but something is not working with it. I'm not the one that has created this metric in the first place, I just hoped I could use it.. can anyone see any obvious mistakes?
// variables available
// current: GlideRecord - target Change
// definition: GlideRecord - (this row)
var s = current.state;
var ss = current.u_sub_state;
// We attach a metric when Change is created
if (current.sys_updated_on == current.sys_created_on)
createMetric();
// If Change state reaches Proposed and Sub-State Awaiting Customer approval we close the metric.
if(s == -7 && ss == 'awaiting_customer_approval')
closeMetric();
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 = false;
gr.insert();
}
function closeMetric() {
var gr = new GlideRecord('metric_instance');
gr.addQuery('id', current.sys_id);
gr.addQuery('calculation_complete', false);
gr.addQuery('definition.type','calculation');
gr.addQuery('definition',definition.sys_id);
gr.query();
while(gr.next()){
// gs.log("==>>DEBUG. Found existing Problem metric. Updating");
// gs.log("==>>DEBUG. closing: "+ gr.definition.name+" for: "+ current.number);
gr.calculation_complete = true;
gr.end = current.sys_updated_on;
gs.log("==>>DEBUG. CHANGE KPI Start: " + gr.start.getDisplayValue());
gs.log("==>>DEBUG. CHANGE KPI End: " + gr.end.getDisplayValue());
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gs.log("==>>DEBUG. " + gr.duration);
gs.log("==>>DEBUG. Updating Metric: " + gr.id);
gs.log("==>>DEBUG. current.sys_id: " + current.sys_id);
// var definition =new GlideRecord('metric_definition');
// definition.get(gr.definition);
// var mi =new MetricInstance(definition, current);
// mi.endDuration();
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2017 04:28 AM
What exactly is not working?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2017 05:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2017 05:03 AM
Where is the current script? In a business rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2017 05:16 AM