- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 03:19 AM
I have a requirement to automatically deactivate users in ServiceNow who haven’t logged in for over 90 days. We want to run a check daily.
Scenario :
Scheduled Business Rule that runs daily, checking the sys_user table for users who haven’t logged in for the specified period and updates their active status.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 07:43 AM - edited 05-13-2025 07:45 AM
> Navigate to 'Scheduled Jobs' from left navigator under system definition menu
> Create New
> Automatically run a script of your choosing
> Set schedule to run daily at some time
> Add below script
var daysInactive = 90;
var cutoffDate = new GlideDateTime();
cutoffDate.addDaysUTC(-daysInactive);
gs.info('Starting User Deactivation Job for users inactive since: ' + cutoffDate.getDisplayValue());
var userGR = new GlideRecord('sys_user');
userGR.addQuery('active', true); // Only active users
userGR.addQuery('last_login', '<=', cutoffDate); // Users who haven't logged in for 90+ days
userGR.query();
var count = 0;
while (userGR.next()) {
userGR.active = false;
userGR.update();
count++;
}
gs.info('User Deactivation Job completed. Total users deactivated: ' + count);
Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 07:43 AM - edited 05-13-2025 07:45 AM
> Navigate to 'Scheduled Jobs' from left navigator under system definition menu
> Create New
> Automatically run a script of your choosing
> Set schedule to run daily at some time
> Add below script
var daysInactive = 90;
var cutoffDate = new GlideDateTime();
cutoffDate.addDaysUTC(-daysInactive);
gs.info('Starting User Deactivation Job for users inactive since: ' + cutoffDate.getDisplayValue());
var userGR = new GlideRecord('sys_user');
userGR.addQuery('active', true); // Only active users
userGR.addQuery('last_login', '<=', cutoffDate); // Users who haven't logged in for 90+ days
userGR.query();
var count = 0;
while (userGR.next()) {
userGR.active = false;
userGR.update();
count++;
}
gs.info('User Deactivation Job completed. Total users deactivated: ' + count);
Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2025 03:03 AM
Did the above solution work? If yes, Accept the solution and mark as helpful to close the thread and benefit other readers.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 09:45 PM
Thanks a lot , it worked! By Execute now it is working , but with time setting it is not updating, don't know why. i have given daily with 00 02 00 this time, i have waited for three days it is not updating.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2025 09:14 AM
Check for scheduled job execution history
Go to table "syslog_transaction" and filter for Type "Scheduler". In column "URL" you find the name of the Job.