- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 11:16 AM
I have implemented a scheduled job in ServiceNow to track and manage inactive users based on their last login time. This ensures that inactive users are properly monitored and notified before deactivation. However, the final notification is not being received by users when using the following query:
Here, date60 is a GlideDate variable that retrieves all users who have not logged in for more than 60 days, and grInactive is a GlideRecord variable.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2025 09:26 PM - edited 03-07-2025 09:27 PM
Here's my approach and it's working as expected.
1. Event registry:
2. Scheduled job:
var user = new GlideRecord('sys_user');
//Active users with last login time is not empty and last login time is before 60 days.
user.addEncodedQuery("active=true^last_login_timeISNOTEMPTY^last_login_timeRELATIVELT@dayofweek@ago@60");
user.query();
while (user.next()) {
//Triggering the event by passing the user record and user sys_id
gs.eventQueue('dormancy.policy.trigger', user, user.sys_id);
// Calling the function to remove user from the groups
this.removeUsersFromGroup(user);
}
// Function to remove users from the group
function removeUsersFromGroup(user_record) {
var group_membership = new GlideRecord('sys_user_grmember');
group_membership.addQuery("user", user_record.sys_id);
group_membership.deleteMultiple();
}
Notification:
Result:
I hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2025 07:41 PM
in your event Queue you should pass the 3rd parameter which is recipient
Ensure in notification Event parm1 contains Recipient = True
gs.eventQueue("user.inactive.60", grInactive, grInactive.email.toString());
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader