We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

isMemberOf not working in notification

VuchiV
Tera Contributor

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: 

answer =  !(current.approver.isMemberOf('b94fa52553920010f255ddeeff7b12c0'));
 
suggest any changes in code
5 REPLIES 5

Tanushree Maiti
Tera Patron

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;

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

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:

  1. Notification trigger

    • Make sure notification is triggered after approver is populated
  2. Approver field

    • Confirm field name = approver (not assigned_to, etc.)
  3. Group sys_id

    • Double-check sys_id is correct

Thanks,

Rithika.ch

Vishal Jaswal
Tera Sage

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!

Ankur Bawiskar
Tera Patron

@VuchiV 

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! 🙏

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