Need help on creating notification

Pradeepa B
Tera Contributor

Requirement is when incident sla (Business elapsed percentage is greater then 75%) and when incident assignment group is ABC1 or ABC2, email should trigger to particular users + incident assignment group(only which group members have title as contractor)

Could you please help me on this requirement?

 

Thank you

16 REPLIES 16

Pradeepa B
Tera Contributor

Hi @Ankur Bawiskar ,

Requirement is when incident sla (Business elapsed percentage is greater then 75%) and when incident assignment group is ABC1 or ABC2, email should trigger to particular users(tester1 and tester2) + incident assignment group(only which group members have Employment Status as contractor).

I have created the notification, when to send as event is fired.

Created the event registry and pulled in even name in the notification.

I have created the business rule, 

PradeepaB_0-1745506922837.png

 

Business rule script: 



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

    var recipients = [];

    // Safely get the assignment group record
    var group = current.task.assignment_group.getRefRecord();
    if (!group || !group.sys_id) {
        gs.log("[Contractor Notify] Invalid assignment group on incident: " + current.number);
        return;
    }

    // Query group members
    var grMember = new GlideRecord('sys_user_grmember');
    grMember.addQuery('group', group.sys_id);
    grMember.query();

    while (grMember.next()) {
        var user = grMember.user.getRefRecord();
        if (user && user.edu_status == 'C') { // Employment Status is Contractor
            if (user.email) {
                recipients.push(user.email.toString());
            }
        }
    }

    if (recipients.length > 0) {
        // Trigger custom event with recipient list
        gs.eventQueue('sla.75percent.notification', current, group.sys_id.toString(), recipients.join(","));
        gs.log("[Contractor Notify] Event triggered for: " + recipients.join(", "));
    } else {
        gs.log("[Contractor Notify] No contractors found in group: " + group.name);
    }

})(current, previous);

Could you please help me on this requirement and script?
 
Thank you

 

@Pradeepa B 

so what logs did you add and debug?

Unless you debug you won't know which line is breaking your script

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Pradeepa B
Tera Contributor

Hi @Ankur Bawiskar ,

 

Notification is working fine, but it's triggering every 2%, how to fix this issue?

@Pradeepa B 

Glad to know that my scripted helped you achieve your requirement.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Pradeepa B 

when should the email be sent?

you should ensure you configure the correct BR conditions

If my response helped please mark it correct and close the thread so that it benefits future readers.

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