Metric for calculation time spent by a group on the ticket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 05:29 AM
Hi,
Need: To calculate and store the time for which a Ticket has been assigned to a particular group and even if it reassigned to the same group again.
Steps: Created a metric on the basis of assignment group but i the duration was coming zero seconds as the start time and end time is the same, but actually it should calculate the time for which the ticket has been assigned to the group.
Thanks for your help!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 06:05 AM
I used this metric script
(function calculateMetric(current, definition, mi) {
// Check to see if a metric instance already exists for this ticket
// assigned to this assignment group
var grMetric = new GlideRecord('metric_instance');
grMetric.addQuery('id', current.getValue('sys_id'));
grMetric.addQuery('definition', definition.getValue('sys_id'));
grMetric.addQuery('value', current.getDisplayValue('assignment_group'));
grMetric.query();
if (grMetric.hasNext()) {
// If so, then this ticket has already been counted for this assignment
// group and there's no need to do anything.
}
else {
// If not, create one
var now = new GlideDateTime();
var instant = new GlideDuration(0);
grMetric = new GlideRecord('metric_instance');
grMetric.initialize();
grMetric.setValue('table', current.getRecordClassName());
grMetric.setValue('id', current.getValue('sys_id'));
grMetric.setValue('definition', definition.getValue('sys_id'));
grMetric.setValue('field', definition.getValue('field'));
grMetric.setValue('value', current.getDisplayValue('assignment_group'));
grMetric.setValue('duration', instant);
grMetric.setValue('business_duration', instant);
grMetric.setValue('calculation_complete', true);
grMetric.setValue('start', now);
grMetric.setValue('end', now);
grMetric.insert();
}
})(current, definition, mi);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 06:06 AM
I used this metric
(function calculateMetric(current, definition, mi) { // Check to see if a metric instance already exists for this ticket // assigned to this assignment group var grMetric = new GlideRecord('metric_instance'); grMetric.addQuery('id', current.getValue('sys_id')); grMetric.addQuery('definition', definition.getValue('sys_id')); grMetric.addQuery('value', current.getDisplayValue('assignment_group')); grMetric.query(); if (grMetric.hasNext()) { // If so, then this ticket has already been counted for this assignment // group and there's no need to do anything. } else { // If not, create one var now = new GlideDateTime(); var instant = new GlideDuration(0); grMetric = new GlideRecord('metric_instance'); grMetric.initialize(); grMetric.setValue('table', current.getRecordClassName()); grMetric.setValue('id', current.getValue('sys_id')); grMetric.setValue('definition', definition.getValue('sys_id')); grMetric.setValue('field', definition.getValue('field')); grMetric.setValue('value', current.getDisplayValue('assignment_group')); grMetric.setValue('duration', instant); grMetric.setValue('business_duration', instant); grMetric.setValue('calculation_complete', true); grMetric.setValue('start', now); grMetric.setValue('end', now); grMetric.insert(); } })(current, definition, mi);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 06:07 AM
All the predefined metric are storing the data sometimes not every time.... I am new to Service Now so not much aware of all these functionalities.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 06:16 AM
Yeah Metric Definitions & Instances are an old utility that has always needed a bit of a facelift.
I'll peek at your script later today.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2018 07:39 AM
Hi Robert,
Did you get time to check the script as I was not able to find any error in it.
Any help will be very thankful.