Reporting on the first time an incident is assigned to an assignment group

mithun1shah
Giga Contributor

Hi All,

I'm trying to capture the first time an incident is assigned to each assignment group.

For example:

Assignment Group                                   Metric

Service Desk                                                         Capture

Incident Management                             Capture

Networks                                                                     Capture

Incident Management                             Don't capture

Databases                                                                 Capture

Networks.                                                                   Don't capture

I know that metrics will capture each assignment, but I just need the first. I assume I need some sort of scripted metric?

Thanks!

Mithun

1 ACCEPTED SOLUTION

Aditya Mallik
ServiceNow Employee
ServiceNow Employee

Mithun,



Out of the box, there is a Metric Definition "Assignment Group" that does almost what you want, but does a bit more than what you want. The out of the box Metric would create a new Metric Instance record each time the assignment group changes, and calculates the duration for which the task record stayed with that assignment group. So if the task record were to be assigned back to the same assignment group again, you will see two Metric Instance records. But nevertheless, you will still be able to sort the records to figure out the first time the task was assigned to that group.



The Metric Instance records would look like below, when the Task assignment changes in the sequence of:   CAB Approval, Database, Network, Database, Hardware.


find_real_file.png



If you want you can always create a script based Metric Definition, that does exactly what you are looking for. The script would look like:



// variables available


// current: GlideRecord -   target incident


// definition: GlideRecord -   (this row)



// Initialize the MetricInstance


var mi = new MetricInstance(definition, current);



// Check if a metric already exists for the current task for assignment group


if (!metricExists()) {


      var gr = mi.getNewRecord();


      gr.field_value = current.getValue(definition.field);


      gr.start = current.sys_updated_on;


      gr.end = current.sys_updated_on;


      gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());


      gr.calculation_complete = true;


      gr.insert();


}



function metricExists() {


      var gr = new GlideRecord('metric_instance');


      gr.addQuery("id", current.sys_id);


      gr.addQuery("definition", definition.sys_id);


      gr.addQuery("field_value", current.getValue(definition.field));


      gr.query();


      return gr.hasNext();


}



find_real_file.png




I am attaching the XML file for the sample Metric Definition, that you can import into your instance and test easily.



The Metric Instance records would look like below, when the Task assignment changes in the sequence of:   CAB Approval, Database, Network, Database, Hardware.


You can see that in this case, there is only one record or Database group, even though task was assigned to Database, multiple times.


find_real_file.png



Hope this helps you.


View solution in original post

8 REPLIES 8

Aditya Mallik
ServiceNow Employee
ServiceNow Employee

Mithun,



Out of the box, there is a Metric Definition "Assignment Group" that does almost what you want, but does a bit more than what you want. The out of the box Metric would create a new Metric Instance record each time the assignment group changes, and calculates the duration for which the task record stayed with that assignment group. So if the task record were to be assigned back to the same assignment group again, you will see two Metric Instance records. But nevertheless, you will still be able to sort the records to figure out the first time the task was assigned to that group.



The Metric Instance records would look like below, when the Task assignment changes in the sequence of:   CAB Approval, Database, Network, Database, Hardware.


find_real_file.png



If you want you can always create a script based Metric Definition, that does exactly what you are looking for. The script would look like:



// variables available


// current: GlideRecord -   target incident


// definition: GlideRecord -   (this row)



// Initialize the MetricInstance


var mi = new MetricInstance(definition, current);



// Check if a metric already exists for the current task for assignment group


if (!metricExists()) {


      var gr = mi.getNewRecord();


      gr.field_value = current.getValue(definition.field);


      gr.start = current.sys_updated_on;


      gr.end = current.sys_updated_on;


      gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());


      gr.calculation_complete = true;


      gr.insert();


}



function metricExists() {


      var gr = new GlideRecord('metric_instance');


      gr.addQuery("id", current.sys_id);


      gr.addQuery("definition", definition.sys_id);


      gr.addQuery("field_value", current.getValue(definition.field));


      gr.query();


      return gr.hasNext();


}



find_real_file.png




I am attaching the XML file for the sample Metric Definition, that you can import into your instance and test easily.



The Metric Instance records would look like below, when the Task assignment changes in the sequence of:   CAB Approval, Database, Network, Database, Hardware.


You can see that in this case, there is only one record or Database group, even though task was assigned to Database, multiple times.


find_real_file.png



Hope this helps you.


Hi Aditya,



Yes, that's perfect! Thanks very much.



Thanks



Mithun


Hi, thanks for this. Please could you detail how this could be modified to capture only the very first/initial assignment of the incident (i.e. the Assignment group value at very first assignment)?

I see the general 'Assignment group' metric definition you refer to but as you say this picks up every assignment. Thank-you!

Hi DJS43,

Did you got any resolution for this? Even i have a similar requirement.

Thanks,

PY