Notification advanced condition script, only send when user is part of a

Bart Jan Bultma
Kilo Sage

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;
}

.

 

 

1 ACCEPTED SOLUTION

@Bart Jan Bultman - Could you please try with the below code if the notification is on table sys_user. 

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

View solution in original post

12 REPLIES 12

Mohith Devatte
Tera Sage
Tera Sage

@Bart Jan Bultman hello 

is this a scoped app ?

also try this script 

if(gs.getUser().isMemberOf('GROUPNAME')) 
{
 answer = true; 
} 
else
 { 
answer = false; 
}

PLEASE MARK MY ANSWER CORRECT IF THIS HELPS YOU

I changed the script to what you provided but the result is the same. I don't think its a scoped app, but how do I check this?

Damini Sheth
Tera Contributor

Hi, you can try this as well,

var ourUser = gs.getUserID();

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', ourUser); // checking user sys id here.
gr.addQuery('group', 'GROUP_SYSID');// enter youe group sys id here
gr.query();

if(gr.next()) {
    answer = true;
}
else {
   answer = false;
}


PLEASE MARK MY ANSWER CORRECT IF THIS HELPS YOU

Unfortunately this doesnt seem to work. It always returns true, both for users that are member of the group, and for users that are not member of the group