Metrics definition for certain group

SM123
Tera Expert

Hello All,

I'm here after Solved: Re: Metrics definition for certain group - ServiceNow Community  

I'm trying to enhance my metric definition. basically, my metric definition will capture the assigned to duration for only "prep group" assignment group members for incident table. i want last assignee's (i mean assigned to person before tickets get reassigned to other group) duration to be empty. Kindly help me with the following code

answer = (function(mi) {
    var incidentGR = mi.current;

    if (incidentGR.getValue('assignment_group') != 'Prep Group sysid') { 
        // End the existing duration field
        mi.endDuration();

        // Find the last metric instance for the same incident and clear its duration
        var metricGR = new GlideRecord('metric_instance');
        metricGR.addQuery('reference', incidentGR.getUniqueValue()); // Link to the same incident
        metricGR.addQuery('duration', '!=', ''); // Ensure we target non-empty durations
        metricGR.orderByDesc('sys_created_on'); // Get the latest metric instance 
        metricGR.query();

        if (metricGR.next()) {
            metricGR.setValue('duration', ''); // Clear the duration field
            metricGR.update(); // Save changes
        }

        // Don't allow the creation of a new metric instance
        return false;
    }

    return true;
}(mi));

 @Kieran Anson please check it out 

5 REPLIES 5

Kieran Anson
Kilo Patron

Hey,

I'm a tad confused. So given the following situation

  • Ticket created to help desk (no prep group) - no metric created
  • Ticket assigned to group of prep group - no metric created
  • Ticket assigned to user in prep group - metric created and time starts
  • Ticket assigned to new group - the above metric is stopped, but time cleared?