Trigger email notification when user has admin role, security admin and or import admin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 09:03 AM
Hello all
I am creating an email notification for when an export is done.
I want this to only trigger if the user has an admin role such as admin, security_admin and import_admin
I have created my event and now creating the notification but not sure what to do with the condition to meet my requirement.
Please see screenshot for what I have done thus far, any help will be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 09:22 AM
If the logged in user should have any of the roles mentioned above, use the Advanced condition field and add below script
answer = false;
if (gs.hasRole("admin") || gs.hasRole("security_admin") || gs.hasRole("import_admin")) {
answer = true;
}
Please mark it as correct if it helps. Let me know incase of any issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 09:28 AM
Hello @Ponda,
You can try adding a script in the advanced condition of the notification similar to the script as shown below -
Code for reference -
function userHasRole() {
var userGr = new GlideRecord("sys_user_has_role");
userGr.addQuery('user', current.session_user); //field on the record who will be the recipient
userGr.addQuery('role.nameINadmin,security_admin,import_admin');
userGr.query();
if (userGr.next()) {
return true;
} else
return false;
}
Please mark this solution as helpful if it helps you 🙂
Best Regards,
Shubha S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 09:45 AM
Where were you going to trigger the event from? I would look at adding the condition in there and only raise the event if the condition is met. No point raising the event if it does not and then checking it in the Notification to see if the email should go out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 11:33 AM
I am sorry, did not understand your statement Jim!
I created and event and I would expect the notification will contain the conditions. Are you saying to have the script within the BR