Help Configuring a Metric Definition to Track Assignment‑Group Duration Across State Changes

DimitrisV
Tera Contributor

Hello everyone,

I’ve created a Metric Definition on the Incident table with a scripted filter that correctly selects only my target Assignment Group(s). It currently records an interval start whenever the ticket enters a new assignment group. However, I’m encountering two issues:

  1. Missing “end” Timestamp on Resolve→Reopen Cycles

    • When the incident’s State transitions from In ProgressResolved (while still in the same Assignment Group), no end timestamp is recorded for the interval.

    • Consequently, if the ticket later moves back ResolvedIn Progress (same group), the metric never “closes” that first interval, so its duration remains open indefinitely.

  2. Closure Only on Incident Close

    • The metric only closes when the incident itself is marked Closed (e.g. after a week), which isn’t helpful for measuring the elapsed time between In Progress and Resolved.

       

      What I Need

      • End the interval whenever State changes In Progress → Resolved for the same Assignment Group, recording date + time.

      • Accumulate durations if the ticket reopens (transition Resolved → In Progress) under the same Assignment Group, appending each new “In Progress” period to the prior total.

      • Alternatively, end and start a fresh interval whenever the Assignment Group itself changes.


      Has anyone implemented a Metric Definition (or Business Rule / Script Include) that:

      • Detects both Assignment‑Group changes and relevant State transitions (two diferent fields)?

      • Records an end timestamp on In Progress → Resolved (in a metric when field is assignment roup)?

      • Accumulates duration across multiple reopen cycles, without waiting until the incident is finally Closed?

      Any sample scripts or configuration guidance would be greatly appreciated. Thanks in advance!

4 REPLIES 4

Mark Manders
Mega Patron

Have you tried creating a database view between the 'state' metric and the 'assignment group' metric definitions? 

It feels like there are some things missing to get a complete picture. You mention it only runs on your selected groups, so what happens if it is changed to a different group (one that is not recorded), or if the state and assignment group change? 
Could you share the script you are using? Maybe that helps to understand the exact business requirement that you are trying to resolve with this.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

DimitrisV
Tera Contributor

 

if (current.sys_class_name == 'incident' && current.assignment_group.getDisplayValue() == 'Network') {
    createMetric();
}

 

function createMetric() {
    var mi = new MetricInstance(definition, current);

 

    if (mi.metricExists()) {
       
        var mi_gr = new GlideRecord('metric_instance');
        mi_gr.addQuery('definition', definition.sys_id);
        mi_gr.addQuery('id', current.sys_id);
        mi_gr.addQuery('calculation_complete', false);
        mi_gr.query();

 

        if (mi_gr.next()) {

 

            mi_gr.end = new GlideDateTime();
            mi_gr.calculation_complete = true;
            mi_gr.duration = gs.dateDiff(mi_gr.start.getDisplayValue(), mi_gr.end.getDisplayValue());
            mi_gr.update();
        }

 

        if (current.assignment_group) {

 

            var gr_change = mi.getNewRecord();
            gr_change.start = new GlideDateTime();
            gr_change.value = current.assignment_group.getDisplayValue();
            gr_change.field_value = current.assignment_group.sys_id;
            gr_change.calculation_complete = false;
            gr_change.insert();
        }
    } else {

 

        if (current.assignment_group) {

 

            var gr_new = mi.getNewRecord();
            gr_new.start = new GlideDateTime();
            gr_new.value = current.assignment_group.getDisplayValue();
            gr_new.field_value = current.assignment_group.sys_id;
            gr_new.calculation_complete = false;
            gr_new.insert();
        }
    }
}

DimitrisV_0-1753345592772.png

this is the script that i use too but i cant take only one field and this is assigment group. As you see the last incident start from service desk and change to network all good but when i made the state resolved the end is not taking any price until its be closed. But in incidents anyone can change the state again to somethink else and i want to count the duration until be resolved in network assigment group



I think that you can only get this to work if you move away from metrics and (mis)use the SLA engine for this. You can run the definitions on any state/group change and record the exact time (even pause it when it goes to another group within the same state and comes back). 
I never like using SLA definitions for reporting purposes, but sometimes it's the only way. 

At one customer, we also had to do this and we even created an extra SLA Definition type for it (not resolve or response, but 'report'). That way they are easily kept out of any (end user facing) reports and you can even easily exclude them from being shown in the related lists.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

DimitrisV
Tera Contributor

i try this too to make a sla_breakdown_assignment in sla which priotity is everythink and there is a solution but it worked only for the new incidents, not retrospectives for old archives and if i could make a repair the old ones, i think this could be a problem for the system. Im try to do it now with business rule and try to check from metric the assigment group and from business rule the state...