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 

then please use event based approach, and get the group members with that title and include in eventQueue() parm1

In notification ensure "Event parm1 contains recipient" is true

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 ,

 

I have created this business rule, but this is not working. I also called in notification.

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

    // Validate conditions: Business percentage > 2 AND Assignment Group is in the specified list
   
    var taskGroup = current.task.assignment_group.getDisplayValue(); // Get group name

    if (current.taskslatable_business_percentage > 1 && validGroups.indexOf(taskGroup) !== -1) {
       
        var arrUsers = [];
       
        // Querying users with title 'Contractor' in the specific assignment group
        var grMember = new GlideRecord('sys_user_grmember');
        grMember.addQuery('group', current.task.assignment_group);
        grMember.query();

        while (grMember.next()) {
            var userRecord = new GlideRecord('sys_user');
            userRecord.get(grMember.user);

            if (userRecord.title == 'Contractor') {
                arrUsers.push(userRecord.email); // Get the user's email instead of sys_id
            }
        }

        // Check if we have users to notify
        if (arrUsers.length > 0) {
            var emailUsers = arrUsers.join(',');

            // Trigger custom event for notification
            gs.eventQueue('sla.75percent.notification', current, current.task.assignment_group.sys_id, emailUsers);
        }
        gs.log('testing');
    }

})(current, previous);

@Pradeepa B 

your event, notification is on which table?

I hope it's on task_sla table

Ensure "Event parm2 contains recipient" is TRUE on notification record

Also this line is wrong -> what is validGroups? what does this mean?

if (current.taskslatable_business_percentage > 1 && validGroups.indexOf(taskGroup) !== -1) {

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

    // Validate conditions: Business percentage > 2 AND Assignment Group is in the specified list

    var taskGroup = current.task.assignment_group.getDisplayValue(); // Get group name

    if (current.taskslatable_business_percentage > 1 && validGroups.indexOf(taskGroup) !== -1) {

        var arrUsers = [];

        // Querying users with title 'Contractor' in the specific assignment group
        var grMember = new GlideRecord('sys_user_grmember');
        grMember.addQuery('group', current.task.assignment_group);
        grMember.query();

        while (grMember.next()) {
            var userRecord = new GlideRecord('sys_user');
            userRecord.get(grMember.user);
            if (userRecord.title.toString() == 'Contractor') {
                arrUsers.push(userRecord.email.toString()); // Get the user's email instead of sys_id
            }
        }

        // Check if we have users to notify
        if (arrUsers.length > 0) {
            var emailUsers = arrUsers.join(',');

            // Trigger custom event for notification
            gs.eventQueue('sla.75percent.notification', current, current.task.assignment_group.sys_id, emailUsers);
        }
        gs.log('testing');
    }

})(current, previous);

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 ,

This script is not working, I also followed the steps.

@Pradeepa B 

sorry but we can only guide and provide scripts which you need to enhance further.

What enhancement you performed?

I already informed what changes are required and the probable issue

AnkurBawiskar_0-1745496269254.png

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