
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2022 03:40 AM
Im kicking off a event from a scheduled job that checks for a users end date daily. If the end date is today, it should send a notification to our ServiceDesk. This part works.
In the Notification I am adding an advanced condition that should only send the notification if the user that is on its end date is a member of a specific group in ServiceNow. I am using the code below but it always returns false and does not send the notification.
var groupMember = gs.getUser();
if(groupMember.isMemberOf('GROUPNAME'))
{
answer = true;
}
else
{
answer = false;
}
.
Solved! Go to Solution.
- Labels:
-
Notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2022 10:39 PM
Note:
1. Assuming you are trying to trigger notification for the user record.
2. Change the variable group_name value and use the code.
var group_name = "Please set your group name here to check";
var user_sys_id = current.sys_id;
var userOb = new GlideUser().getUserByID(user_sys_id);
if (userOb.isMemberOf(group_name)) {
answer = true;
} else {
answer = false;
}
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2022 03:55 AM
Try using group sys_id instead of group name.
Let me know if you have any further questions.
Please mark this as Correct or Helpful based on the impact.
Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2022 04:07 AM
Hello Abhijit,
I tried it with sys_id instead of name but the result is the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2022 04:10 AM
if its as scoped app is member of wont work you need to follow below script
IF YES THEY YOU CAN TRY THIS SCRIPT
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user',gs.getUserID());
gr.addQuery('group', 'gorup_sys_id');
gr.query();
if(gr.next()) {
answer = true;
}
else {
answer = false;
}
hope this helps you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2022 04:27 AM
Hello
I'm only using a scheduled job, global event and notification. I did not do anything with scope. Should I change that and how/where do I do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2022 04:12 AM
Which table you have written a notification. If that table contains a field that referenced to the sys_user table then you can use the below code in advanced script
var user_sys_id = current.field_name;
var userOb = new GlideUser().getUserByID(user_sys_id);
if (userOb.isMemberOf("GROUPNAME")) {
answer = true;
} else {
answer = false;
}
Thanks & Regards,
Vasanth