MTTN Calculation — Incident Task Assignment Not Populating MTTN on Parent Incident

dattanarend
Tera Expert

As part of the Major Incident Management implementation, we have a requirement to calculate MTTN (Mean Time to Notify) — the time between when the Major Incident group is assigned and when the first communication notification is sent by the MIM team.


How MTTN is Calculated:

  • T1 — When the Incident or Incident Task assignment_group is first set to one of the two MIM groups ( Group A or Group B)
  • T2 — When the first communication notification work note appears on the Incident, identified by subject line keywords such as Subject: Major, Subject: Incident Communication  like this we have keywords
  • Result — TTN = T2 minus T1, stored in a custom Duration field MTTN on the parent Incident record under the PIR tab

What We Have Achieved (Case 1 — Working):

When a Major Incident is raised and the assignment_group on the Incident is set to one of the MIM groups (proposed_on or promoted_on timestamps are used as T1), and the first communication notification is logged as a work note on the same incident — the MTTN is calculated correctly and populated in MTTN via a Business Rule on the incident table.


What We Are Facing (Case 2 — Not Working):

For ongoing P3/P4 incidents that do not go through the Proposed or Promoted state, the MIM team creates an Incident Task and assigns it to one of the MIM groups. The agent then sends the communication notification which gets logged as a work note on the parent Incident (not on the task).

In this case:

  • T1 should be captured from sys_audit — when the assignment_group on the incident_task was assigned to one of the MIM groups
  • T2 should be captured from sys_journal_field — first matching work note on the parent Incident after T1
  • The result should be written to MTTN on the parent Incident

We have created a Business Rule on the incident_task table to handle this, but the field is not getting populated on the parent Incident record.


Additional Complexity — Which Comes First:

There is an additional scenario to handle — we need to determine which assignment happened first, either:

  • The Incident itself was assigned to the MIM group first, OR
  • The Incident Task was assigned to the MIM group first

Whichever assignment happened earliest should be treated as T1 for the MTTN calculation, to ensure accuracy.

Any suggestions or guidance would be greatly appreciated.

Thanks in advance!

2 REPLIES 2

Tanushree Maiti
Tera Patron

Hi @dattanarend 

 

Refer this link ,if helps:https://www.servicenow.com/community/itsm-forum/mttd-calculation-time-taken-from-incident-creation-t...

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

GokulNathV
Tera Contributor

Hi @dattanarend 

Please refer if this solution would suffice 

A single BR on the Incident Table with Worknotes Changes

GokulNathV_0-1779091330188.png

 

The condition field is controlled using keyword critical communication (Please change it to your own use case: But this should be a common phrase for the notification or append a common phrase and use it in the BR) 

 

GokulNathV_1-1779091416329.png


Logic : 


if the incident is tagged with the critical group and then holds the keyword work note, we are calculating as per your provided logic. IF not then we check if the incident task is tagged to those critical groups and then pick up those details and calculate.

Both logi share a common function. 

The hardcoded sys id can be made dynamic with a system property based on your use case 

Condition 

 

(current.work_notes.changes())  && (current.work_notes.getJournalEntry(-1).toLowerCase().indexOf('critical communication') > -1) 

 

Code 

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

    try {

        //Logic for Parent record changes

        var getAssignmnetGrp = current.getValue('assignment_group');
        if ((getAssignmnetGrp == '4990262b83b88f10f595ffd6feaad3bf') || (getAssignmnetGrp == '2c806ee783744350f595ffd6feaad39a')) {
            var latestWorkNote = current.work_notes.getJournalEntry(1);
            latestWorkNote = latestWorkNote ? latestWorkNote.replace(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/, '') : "";
            gs.log('Work Notes added ' + latestWorkNote);
            var incidentRec = current.sys_id;
            var incidentUpdatedTime = current.sys_updated_on;
            updateMeanTime(incidentRec, incidentUpdatedTime);


        } else {

            //if the group is changed on the child task

            var incTask = new GlideRecord("incident_task");
            incTask.addEncodedQuery('universal_request=' + current.sys_id + '^universal_request.sys_idSTARTSWITH' + current.sys_id + '^active=true^assignment_groupIN2c806ee783744350f595ffd6feaad39a,4990262b83b88f10f595ffd6feaad3bf');
            incTask.query();
            if (incTask.next()) {
                var incidentParent = current.universal_request.sys_id;
                var incidentParentUpdatedTime = current.universal_request.sys_updated_on;
                updateMeanTime(incidentParent, incidentParentUpdatedTime);

            }

        }


    } catch (ex) {
        gs.log('Error From First Communication Details ' + ex);
    }


    function updateMeanTime(incidentRec, incidentUpdatedTime) {

        var gr = new GlideRecord("sys_audit");
        //adding maximum filters to limit results 
        //@narendra Add created on last 1 hours or 30 minutes as well if the comment is added shortly after the assignment group change
        gr.addEncodedQuery("documentkey=" + incidentRec + "^fieldname=assignment_group^newvalueIN2c806ee783744350f595ffd6feaad39a,4990262b83b88f10f595ffd6feaad3bf");
        gr.orderByDesc('sys_created_on');
        gr.setLimit(1);
        gr.query();
        if (gr.next()) {

            gs.info('Incident of intrest ' + current.number)
            gs.info('Incident Updated ' + (current.sys_updated_on));
            gs.info('comment  Updated ' + (gr.sys_created_on));

            var workNoteAddedTime = gr.sys_created_on;

            var time1 = new GlideDateTime();
            time1.setValue(incidentUpdatedTime);
            var time2 = new GlideDateTime();
            time2.setValue(workNoteAddedTime);

            var duration = GlideDateTime.subtract(time1, time2);
            var exactSeconds = Math.abs(duration.getNumericValue());
            var cleanDuration = new GlideDuration(exactSeconds);
            gs.info("Mean Time of First Communication for Incident " + cleanDuration.getDisplayValue());

            return cleanDuration.getDisplayValue();

        }



    }



})(current, previous);

 

 

Tried Executing and works perfectly 

GokulNathV_2-1779091637082.png



Hope this works