Track Assignment Group Changes with Metric Definition

Praveenapatel
Tera Contributor

By default, ServiceNow provides the Assignment Group metric definition to track the current assignment group value of a record. However, this out-of-the-box (OOB) metric only records the present value and does not capture both the old and new values when the assignment group changes.

 

To support improved auditing and reporting, we can configure a custom metric definition along with an additional field on the Metric Instance table. This enhancement allows us to track both the previous and current assignment group values whenever the field changes on Incident table and can also be used for reporting to know the duration of different groups for specific record (or other tables, if required).

 

Procedure

 

Step 1: Create a field for Old Value

 

  1. Navigate to System Definition > Tables.
  2. Open the Metric Instance [metric_instance] table.
  3. Create a new field:
    • Column Label: Old Value
    • Column Name: u_old_value
    • Type: String

This field will store the previous assignment group value.

 

Step 2: Create a Metric Definition

 

  1. Navigate to Metric Definitions (metric_definition.list).
  2. Click New and provide the following details:
    • Name: Assignment Group Changes
    • Applies to Table: Incident
    • Field: assignment_group
    • Type: Field Value Duration
  3. Copy the Sys ID of the metric definition.

Praveenapatel_1-1758045950573.png

 

Step 3: Store the Metric Definition Sys ID in a Property

 

  1. Navigate to System Properties > All Properties.
  2. Create a new property:
    • Name: assignment.group.metric.sys_id
    • Type: String
    • Value: (Paste the Sys ID from Step 2)
  3. Save the property.

Step 4: Create a Business Rule on the Incident Table

 

  1. Navigate to System Definition > Business Rules.
    • Name: Track Assignment Group Changes
    • Table: Incident
    • When: Before
    • Update: Checked
    • Condition: current.assignment_group.changes()
  2. In the Advanced section, add the following script:

 

(function executeRule(current, previous /*null when async*/) {

 

insertMetrics();

 

function insertMetrics() {

    var mi = new GlideRecord('metric_instance');

    

 

    var metricSysID = gs.getProperty("assignment.group.metric.sys_id");

    mi.initialize();

    mi.definition = metricSysID;

    mi.value = current.assignment_group.getDisplayValue();

    mi.u_old_value = previous.assignment_group.getDisplayValue();

    mi.start = previous.sys_updated_on;

    mi.end = gs.nowDateTime();

    mi.duration = gs.dateDiff(mi.start, mi.end);

    mi.id = current.sys_id;

    mi.table = current.getTableName();

    mi.field = "assignment_group";

    mi.field_value = current.assignment_group;

    mi.calculation_complete = true;

    mi.insert();

}

})(current, previous);

 

Output :

 

When the Assignment Group on an Incident record is changed, a new Metric Instance record is created using custom Metric Definition we created showing the old group, new group, start time, end time, and duration. These records can then be used in reports to see how long each Incident stayed with different groups.

 

Praveenapatel_0-1758045870128.png

 

 

 

 

 

0 REPLIES 0