Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need to Display SLA due(Duration field) in email notification, I am using notification scrip

Reddymahesh
Tera Contributor

PFA below notification script, which I am using.

 

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

    // Add your code here
    var gr = new GlideRecord('task_sla');
    gr.addQuery('sla', '4a9c3e2c87a751900303f659dabb359c');
    gr.addQuery('task', current.sys_id);
    gr.query();

    if (gr.next()) {
        var businessTimeLeft = gr.business_time_left.getDisplayValue();

        var daysInSeconds = 86400; // 1 day = 86400 seconds
        var hoursInSeconds = 3600; // 1 hour = 3600 seconds
        var minutesInSeconds = 60; // 1 minute = 60 seconds

        var days = (businessTimeLeft / daysInSeconds) | 0;
        businessTimeLeft -= days * daysInSeconds;

        var hours = (businessTimeLeft / hoursInSeconds) | 0;
        businessTimeLeft -= hours * hoursInSeconds;

        var minutes = (businessTimeLeft / minutesInSeconds) | 0;
        var seconds = businessTimeLeft % minutesInSeconds;

        var durationValue = "Days " + days + " Hours " + hours + " Minutes " + minutes + " Seconds " + seconds;
        template.print(durationValue);
    }
})(current, template, email, email_action, event);
0 REPLIES 0