Need help on notification creation

Pradeepa B
Tera Contributor

Hi,

 

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-1745505759900.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

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Pradeepa B 

What's the point of creating a new question when already there is discussion going on your earlier thread?

Need help on creating notification 

Members are here to help you and guide you, they will provide sample scripts and that may not be the exact one which your customer wants.

you can always enhance it further and this will help you learn and debug and explore further in ServiceNow.

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 

Hope you are doing good.

Did my reply answer your question?

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