isMemberOf not working in notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Requirement is not sending a notification in case approver is part of specific group. Please find the code I used in notification advanced condition which is not working it seems. Even if approver part of group mentioned, it is sending the notification. Notification is on Approval[sysapproval_approver] table.
script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @VuchiV
Simplest way to do it :
Navigate to System Notifications > Email > Notifications.
Open the notification for approval requests (on sysapproval_approver).
In the When to send tab, add a condition:
- Approver.Group | Is Not | <Name of your Group>
Alternatively, use a script in the Advanced condition field:
var isMember = gs.getUser().getUserByID(current.approver).isMemberOf('<Group_sys_id>') ;
answer = !isMember;
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
hi @VuchiV ,
please find the below updated code -
answer = true; // default send
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', current.approver);
gr.addQuery('group', 'b94fa52553920010f255ddeeff7b12c0');
gr.query();
if (gr.hasNext()) {
answer = false; // stop notification
}NOTE -
Check these 3 things if still not working:
Notification trigger
- Make sure notification is triggered after approver is populated
Approver field
- Confirm field name = approver (not assigned_to, etc.)
Group sys_id
- Double-check sys_id is correct
Thanks,
Rithika.ch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hello @VuchiV
It is important to first understand why it is not working. If you look at your code, you are using "current." which is a GlideElement (explained here) however, "isMemberOf()" method is of GlideUser (explained here)
You can use below code in the advanced condition:
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('user', current.approver);
grMem.addQuery('group', '019ad92ec7230010393d265c95c260dd'); //recommended to create system property like group.name.sysid and specify here as grMem.addQuery('group', gs.getProperty('group.name.sysid'));
grMem.query();
answer = !grMem.hasNext();
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
this should work
answer = gs.getUser().getUserByID(current.approver.toString()).isMemberOf('b94fa52553920010f255ddeeff7b12c0');
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader