- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 12:15 PM
Hello,
I have a requirement - when a local admin in PROD environment logs into the instance, a notification should be sent. I tried following the existing threads, but I am not able to trigger the notification. Here are few things I performed before I posted this question here in this forum.
- Instance Security center - tried looking for notifications which were mentioned in the previous threads - Unable to locate them in preferences from profile.
- Tried the same script that is suggested, but what is the event that needs to be triggered?
- Mail script for content of the email?
Please help.
Thanks
Solved! Go to Solution.
- Labels:
-
Architect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2024 04:38 AM
I see on the image you have selected send when 'Event is fired', it should be changed to 'Record inserted or updated', and also the script requires a change. Here is what you can try out -
1. Notification should be on the sys_user table
2. Update the when to run conditions as below
3. Use the below-mentioned script for the advanced condition -
function userHasAdminRole(userId) {
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', userId);
gr.addQuery('role.name', 'admin');
gr.query();
// Check if any records were returned
if (gr.next()) {
return true; // User has the admin role
} else {
return false; // User does not have the admin role
}
}
// Example usage
var userId = gs.getUserID(); // currently logged in user
var isAdmin = userHasAdminRole(userId);
answer = isAdmin;
I have tested this and it works so should be straightforward for you.
-Harneet Sital
Request you please mark my answer as helpful or correct based on the impact
Find all my ServiceNow articles here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 01:52 AM
Hi @now developer the setup looks good, can you check if the individuals who you have added as users have an email id? Try adding your personal id or user account and see if the email is sent out.
Secondly, are the email notifications enabled on your platform? You can check these email properties.
Let me know and we can try other options if these don't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2024 09:38 PM
Can you please check in the preference settings, if enable notification is enabled for the users for which you are testing the notification.
Please Mark my answer as helpful if it helped you in resolving the issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2025 08:00 PM
Hi, I'm having issue where the above is not triggering the notification. Can someone please explain what does the following part do inside the advanced condition:
// Example usage var isAdmin = userHasAdminRole(userId); answer = isAdmin;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 05:04 PM
Another solution to this is to create the notification for insert on table sn_vsc_login_event where all admin logins are clearly marked.
You would no longer need advanced conditions and all that script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 05:32 PM
This is brilliant! Thanks a lot!