MIM Duration back end value access

Mounika B1
Tera Contributor

Hi team,
I am trying to fetch the MIM workbench  Duration back end value.
I have searched the table name sn_major_incident  table i am unable to find the table name.
I am trying to call this value in ITC email template.Please let me know 

 

 

 

Thanks
Mounika B

 
 
 
 

 

 

 

1 REPLY 1

Naveen20
ServiceNow Employee

The Duration value you see on the MIM Workbench isn't a stored field on any table — it's a calculated value rendered by the UI component in real time. That's why you can't find it in the sn_major_incident or incident table.

It's computed as the elapsed time between when the incident became a Major Incident and the current time (or resolved time).

To use it in your ITC email template, you'll need a mail script that calculates the duration on the fly. Here's how:

1. Create a Mail Script (Navigate to System Notification > Email > Notification Email Scripts)

 
 
javascript
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

    // 'current' here is the communication task (sn_comm_task)
    // Dot-walk to the parent major incident
    var incGR = new GlideRecord('incident');
    incGR.addQuery('sys_id', current.task); // or current.parent depending on your relationship
    incGR.query();

    if (incGR.next()) {
        var startTime = incGR.getValue('major_incident_state_changed_on') 
                        || incGR.getValue('opened_at');
        
        var start = new GlideDateTime(startTime);
        var now = new GlideDateTime();
        
        var duration = GlideDateTime.subtract(start, now);
        
        // duration is a GlideDuration object
        var days = duration.getDayPart();
        var hours = duration.getRoundedDayPart() ? 
                    new GlideDuration(duration.getNumericValue()).toString() : 
                    duration.getDisplayValue();

        // Format as DD:HH:MM:SS
        var totalSeconds = Math.floor(duration.getNumericValue() / 1000);
        var dd = Math.floor(totalSeconds / 86400);
        var hh = Math.floor((totalSeconds % 86400) / 3600);
        var mm = Math.floor((totalSeconds % 3600) / 60);
        var ss = totalSeconds % 60;

        var formatted = _pad(dd) + ':' + _pad(hh) + ':' + _pad(mm) + ':' + _pad(ss);
        template.print(formatted);
    }

    function _pad(n) {
        return (n < 10 ? '0' : '') + n;
    }

})(current, template, email, email_action, event);

2. Reference it in your ITC email template using:

${mail_script:your_script_name}