Change Metric - Change processed by Assignment Groups

MT247
Tera Expert

All,

i am trying to put a metric together, which is recording all the workgroups a change has been assigned to.
I was using a script by Dennis R from this community called Incident Touched as basis, for unknown reasons it is refusing to work for me.

I have created the following metric definition:

find_real_file.png

And used the script from Dennis R which is working fine in incident management:

/**
* Creates a metric to record that an assignment group touched an incident.
* Does not create duplicate metrics if an incident is assigned to an
* assignment group multiple times.
*
* Parameters
*   These parameters are passed into all metric definition scripts.
*
*   current
*       The current record that triggered the metric definition
*
*   definition
*       The metric definition being triggered
*
*   mi
*       A MetricInstance object (see the MetricInstance script include for more
*       information and documentation). I'm not a big fan of using the mi object
*       because it doesn't really contain complete functionality or the ability
*       to customize metrics to the extent that a custom script normally
*       demands.
*
* Created by Dennis R
* 2017-08-16: Initial creation
*/
(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.addQuery('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);

 

Anyone having a clue, why this is not working in change??

 

Cheers

Michael

1 ACCEPTED SOLUTION

Adam Stout
ServiceNow Employee
ServiceNow Employee

Are you reporting on the incident.assignment group?  You need to report on the metric.value (which has all the various groups)

View solution in original post

5 REPLIES 5

Adam Stout
ServiceNow Employee
ServiceNow Employee

Why not just have a normal (non-scripted) duration metric on assignment group and then count distinct per change?

MT247
Tera Expert

Hi Adam, using this gives me the report using the assignment group definition only the last group the change was in.

In the metric definition i have all groups listed, the change has been routed to, but in the report on the change metric table using the definition i am only getting the last group shown mulitple times (as ofter as the assignment group for the change was changed).

 

Adam Stout
ServiceNow Employee
ServiceNow Employee

Are you reporting on the incident.assignment group?  You need to report on the metric.value (which has all the various groups)

MT247
Tera Expert

Thanks Adam.

You made my day!!