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.
2 REPLIES 2

GlideFather
Tera Patron

ahoy @VuchiV,

 

I checked and the isMemberOf() seems to necessarily require connection with gs.getUser() as it is returning logged-in user. If you use dot walking as "current.approver..." it doesn't do the trick or it must be written differently.

 

Tested in my PDI

  • Lines 1 to 8 are having hardcoded sys id and return "2" saying that this sys Id is not a member of that group,
  • Lines 10 to 15 have the gs.getUser()

GlideFather_1-1778513628359.png

 

Try to extend this for the sys_approver logics.. 

var myID = new GlideRecord("sys_user");
if (myID.get("your_sys_ID"))
gs.print('myID: ' + myID.sys_id);

if (myID.isMemberOf('group_sys_ID')) {
    gs.print('myID is a member');
} else {
    gs.print('myID is NOT a member');
}
gs.print('gs.getUserID: ' + gs.getUserID());
if (gs.getUser().isMemberOf('group_sys_ID')) {
    gs.print('getUserID is a member');
} else {
    gs.print('getUserID NOT a member');
}

 

_____
Answers generated by GlideFather. Check for accuracy.

Vishal Jaswal
Tera Sage

Hello @VuchiV 

Seems like a duplicate to an active thread created by you: https://www.servicenow.com/community/itsm-forum/ismemberof-not-working-in-notification/td-p/3540689 

You can find my response in above thread.


Hope that helps!