Do not send notification to manager when manager is member of group

suvarna sonar2
Tera Contributor

I have requirement when group manager is member of group then that user should not received notification. I have done this one through Event triggered. Event is triggering but notification is not getting sent. Could you please check below code. Business rule on the incident table for the after insert as notification on incident table. 

 

var group = current.assignment_group;
var groupManager = group.manager;
 var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', group.sys_id);  
grMember.addQuery('user','!=', groupManager);  
grMember.query();
 while(grMember.next()) {
   gs.eventQueue('exculde.manager',grMember,grMember.user.sys_id);
   // }
}
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@suvarna sonar2 

Ensure these things

1) event is on incident table

2) notification is on incident table and fired when event is processed

a) Send to event creator - true

b) event parm1 contains recipient - true

something like this

var userArr = [];
var group = current.assignment_group;
var groupManager = group.manager.toString();
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', group.sys_id);
grMember.query();
while (grMember.next()) {
    if (grMember.group.exclude_manager.toString() == 'true' && groupManager == grMember.getValue('user')) {
        // do nothing for this user as it's manager who is member and exclude flag is true
    } else {
        userArr.push(grMember.user.toString());
    }
}
gs.info('Manager is excluded from the notification.');
gs.eventQueue('Exclude.manager', current, userArr.toString());

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@suvarna sonar2 

Ensure these things

1) event is on incident table

2) notification is on incident table and fired when event is processed

a) Send to event creator - true

b) event parm1 contains recipient - true

something like this

var userArr = [];
var group = current.assignment_group;
var groupManager = group.manager.toString();
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', group.sys_id);
grMember.query();
while (grMember.next()) {
    if (grMember.group.exclude_manager.toString() == 'true' && groupManager == grMember.getValue('user')) {
        // do nothing for this user as it's manager who is member and exclude flag is true
    } else {
        userArr.push(grMember.user.toString());
    }
}
gs.info('Manager is excluded from the notification.');
gs.eventQueue('Exclude.manager', current, userArr.toString());

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

It Is working but when exclude manager is false so that time notification is going to group members only not to the group manager. As per the OOB it should trigger to the manager.