- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 04:36 AM
hi guys..
I have seen this script in the metric definition....could you please explain this..
here current is incident record..
// script can set answer to false to terminate processing of the metric
// mi - MonitorInstance
// answer
if (!current.active) {
answer = false;
mi.endDuration();
closeDurations(mi.current);
}
function closeDurations(current) {
var gr = new GlideRecord('metric_instance');
gr.addQuery('id', current.sys_id);
gr.addQuery('calculation_complete', true);
gr.addQuery('definition.type', 'field_value_duration');
gr.query();
while (gr.next()) {
var definition = new GlideRecord('metric_definition');
definition.get(gr.definition);
var mi = new MetricInstance(definition, current);
mi.endDuration();
}
}
is this retrieving records from incident that are open?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 04:25 AM
Hi,
// script can set answer to false to terminate processing of the metric
// mi - MonitorInstance
// answer
if (!current.active) { //if the active field in the current record has the value "false",
answer = false; //set answer to false
mi.endDuration(); //call endDuration() function , this function is in Script Includes
closeDurations(mi.current); call the function closeDurations by passing current record
}
function closeDurations(current) {
var gr = new GlideRecord('metric_instance'); //glide record metric instance table
gr.addQuery('id', current.sys_id); //get the record whose id matches current sysid and
gr.addQuery('calculation_complete', true); the field value "calculation complete" to true
gr.addQuery('definition.type', 'field_value_duration'); and "definition type" as "field value duration"
gr.query();
while (gr.next()) {
var definition = new GlideRecord('metric_definition'); //glide through metric definintion table
definition.get(gr.definition);
var mi = new MetricInstance(definition, current);
mi.endDuration();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 04:46 AM
I believe above script gives you the duration through metric about type of fields of incident ( gr.addQuery('definition.type', 'field_value_duration'); ) used on incident . going by the first line of code and as you said this is for incident i dont think it retrievs records when incident is Active.
Lets say for an incident you choose group A -5 and group B- 2 time in your entire ticket flow . At the end after incident gets inactive this will give you time duration of Group A was used there in your incident .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 04:25 AM
Hi,
// script can set answer to false to terminate processing of the metric
// mi - MonitorInstance
// answer
if (!current.active) { //if the active field in the current record has the value "false",
answer = false; //set answer to false
mi.endDuration(); //call endDuration() function , this function is in Script Includes
closeDurations(mi.current); call the function closeDurations by passing current record
}
function closeDurations(current) {
var gr = new GlideRecord('metric_instance'); //glide record metric instance table
gr.addQuery('id', current.sys_id); //get the record whose id matches current sysid and
gr.addQuery('calculation_complete', true); the field value "calculation complete" to true
gr.addQuery('definition.type', 'field_value_duration'); and "definition type" as "field value duration"
gr.query();
while (gr.next()) {
var definition = new GlideRecord('metric_definition'); //glide through metric definintion table
definition.get(gr.definition);
var mi = new MetricInstance(definition, current);
mi.endDuration();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2018 09:17 AM
tq so much