Creating a fully automated email notification for Incident tickets.

EdmarM
Giga Contributor

Create a fully automated email notification for Incident tickets.  However despite having the First Strike, Second Strike and Third Striked all setup. The email is email is is still not showing. Below is my script for the Business Rule

 

(function executeRule(current, previous) {
 
    // Only run for Service Desk incidents
    if (current.assignment_group.getDisplayValue() != 'Service Desk') {
        return;
    }
 
    // Only run for Awaiting Customer state
    // Your Awaiting Customer value is 109
    if (current.state.toString() != '109') {
        return;
    }
 
    var now = new GlideDateTime();
    var attempts = current.u_contact_attempts.toString();
 
    // =========================
    // FIRST STRIKE
    // Trigger:
    // Contact Attempts = 0
    // =========================
    if (attempts == '0') {
 
        current.u_contact_attempts = '1';
        current.u_last_contact_date = now;
        current.u_next_contact_date = addBusinessDays(now, 5);
 
        gs.eventQueue(
            'incident.first.strike',
            current,
            '',
            ''
        );
 
        gs.addInfoMessage('First Strike executed. Contact Attempts changed to 1.');
        return;
    }
 
    // =========================
    // SECOND STRIKE
    // Trigger:
    // Contact Attempts = 1
    // Next Contact Date changed to today/past
    // =========================
    if (attempts == '1') {
 
        if (current.u_next_contact_date.changes() &&
            isNextContactDue(current.u_next_contact_date, now)) {
 
            current.u_contact_attempts = '2';
            current.u_last_contact_date = now;
            current.u_next_contact_date = addBusinessDays(now, 5);
 
            gs.eventQueue(
                'incident.second.strike',
                current,
                '',
                ''
            );
 
            gs.addInfoMessage('Second Strike executed. Contact Attempts changed to 2.');
        }
 
        return;
    }
 
    // =========================
    // THIRD STRIKE / FINAL
    // Trigger:
    // Contact Attempts = 2
    // Next Contact Date changed to today/past
    // =========================
    if (attempts == '2') {
 
        if (current.u_next_contact_date.changes() &&
            isNextContactDue(current.u_next_contact_date, now)) {
 
            current.u_contact_attempts = '3';
            current.u_last_contact_date = now;
            current.u_next_contact_date = '';
 
            // Resolved state value
            current.state = '6';
 
            // Optional resolution fields
            current.close_code = 'Solved (Work Around)';
            current.close_notes = 'Resolved after third customer contact attempt.';
 
            gs.eventQueue(
                'incident.third.strike',
                current,
                '',
                ''
            );
 
            gs.addInfoMessage('Third Strike executed. Incident resolved.');
        }
 
        return;
    }
 
 
    // =========================================
    // Function: check if Next Contact Date is today or past
    // =========================================
    function isNextContactDue(nextContactDate, today) {
 
        if (nextContactDate.nil()) {
            return false;
        }
 
        var nextDate = new GlideDateTime(nextContactDate);
 
        if (nextDate.getNumericValue() <= today.getNumericValue()) {
            return true;
        }
 
        return false;
    }
 
 
    // =========================================
    // Function: add 5 business days
    // Skips Saturday and Sunday
    // =========================================
    function addBusinessDays(startDate, daysToAdd) {
 
        var newDate = new GlideDateTime(startDate);
        var addedDays = 0;
 
        while (addedDays < daysToAdd) {
 
            newDate.addDaysLocalTime(1);
 
            var dayOfWeek = newDate.getDayOfWeekLocalTime();
 
            // 1 = Monday
            // 2 = Tuesday
            // 3 = Wednesday
            // 4 = Thursday
            // 5 = Friday
            // 6 = Saturday
            // 7 = Sunday
            if (dayOfWeek != 6 && dayOfWeek != 7) {
                addedDays++;
            }
        }
 
        return newDate;
    }
 
})(current, previous);
3 REPLIES 3

Tanushree Maiti
Tera Patron

Hi @EdmarM 

 

In your gs.eventQueue , parm1   is empty.

where

gs.eventQueue('event.name', GlideRecord, parm1, parm2); // standard form

 

If you already know the recipient group, you can directly pass that group's mail_id in #parm1 and set the receiver to EVENT PARM 1.

Alternatively, you can select the recipient group from the Who will receive it tab, as shown below:

 

gs.eventQueue('incident.comment.added', current, recipientEmail, '');

TanushreeMaiti_0-1784256891187.png

 

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

ajmalmuhamm
Tera Contributor

Hi @EdmarM ,

In addition to what has already been suggested, I'd recommend verifying a couple of things.

In your script, you're calling:

gs.eventQueue('incident.first.strike', current, '', '');

Here, both parm1 and parm2 are empty. If your notification is configured to send to Event parm 1, no recipient email is being passed, so the notification won't be sent.

If you already know the recipient, you can pass the email address in parm1, for example:

gs.eventQueue('incident.first.strike', current, recipientEmail, '');

Alternatively, if your notification is configured to send recipients from the Who will receive tab (Users, Groups, Assigned to, Caller, etc.), then you don't need to use parm1. Instead, verify that:

  • The event name in the Business Rule exactly matches the registered event.

  • The notification is triggered by the same event.

  • The notification is active.

  • The intended recipient has a valid email address and notifications are enabled.

  • The event is actually being generated (check System Logs > Events) and whether the notification appears under System Mail > Email.

A good first step is to check whether the event is being created successfully. If the event exists but no email is generated, the issue is most likely with the notification configuration or recipient settings rather than the Business Rule itself.

Ankur Bawiskar
Tera Patron

@EdmarM 

check this link which uses flow

[How to] Flow 3 Strike rule for Incident 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader