Notification table advance condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-31-2021 06:53 PM
Hi All,
Configured email notification ( table as sys_user) table to send users mail notification
We dont want to send certain group and role exclude users (
Any Idea to add condtion in the advance condition ? saying that group is not xxx and role is not yyy in Notification ( sys_user)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-31-2021 07:26 PM
Hi,
Can you give an example use case of what the plan is for this notification being on the sys_user table.
Do you mean a use case is:
I create a new sys_user so then send them a notification? So I don't want to send the notification if they're a member of 'x' group. I also don't want to send it if they have 'y' role?
Your post is a bit confusing as far as what you're trying to do...or maybe I'm just misreading it.
This script here would not send the notification if the user's record that triggered this notification is a member of 'x' group AND also they don't have role 'y':
var user = current.user_name;
var group = 'group name';
var uRole = 'role_name';
if (gs.getUser().getUserByID(user).isMemberOf(group) && gs.getUser().getUserByID(user).hasRole(uRole)){
answer = false;
} else {
answer = true;
}
So the above script is checking BOTH their group membership and role and if they are a member of 'x' group AND...they also have 'y' role, then the notification WILL NOT be sent.
Please adjust as you need, the above is merely an example.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-31-2021 07:45 PM
Can we Include parent group name in this script ? like var parent = group.parent.name ?
because In parent group , there are 20+ groups available , which is needs to exclude

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-01-2022 12:36 PM
Hello,
If my reply above was Helpful, please mark it as such.
Each group would need to be evaluated to check and see if they're a member.
Also, as a side note, please state as clearly as possible how complex this may be when you post a question. This helps us...help you. You refraining from giving that information originally invalidates the initial replies you got because we wrote them per what you said in your post, which made it sound like 1 group and their membership. Not...20 groups, as child groups of a parent group, etc.
With what you've said now...you'd need to use GlideRecord and query through the parent and then child groups that have the same parent and if they are a member of any of them, then do 'x', else do 'y'. Or...build an array with all of the groups (which isn't necessarily the best way to handle this because groups (parent/child relationships can change) and loop through just those in the array and check if they're a member and then proceed or not.
Please refer to documentation and then my original example above for how to handle this: https://developer.servicenow.com/dev.do#!/reference/api/quebec/server/no-namespace/c_GlideRecordScop...
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-31-2021 07:27 PM
Hi,
You can write something like this in advanced condition.
if (gs.getUser().getUserByID(current.sys_id.toString()).hasRole("<role>") || gs.getUser().getUserByID(current.sys_id.toString()).hasRole("<another role>")) {
if (gs.getUser().getUserByID(current.sys_id.toString()).isMemberOf("<group1>") || gs.getUser().getUserByID(current.sys_id.toString()).isMemberOf("<group2>")) {
answer = false;
} else {
answer = true;
}
} else {
answer = false;
}
Please mark my answer as correct answer & helpful if applicable.
Thanks,
Narsing