Deactivate users if not logged for 90 days and check if the users has any opened tickets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2025 08:43 AM
Hi All,
I need assistance in scheduled job script to inactivate users who didn't log into system for 90 days and make them inactive. Also, check if the users inactivated has any opened tickets(Task Table), if yes create an incident to a dedicated group.
Can someone assist with the script please?
Thanks
Shan
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2025 09:09 AM
In sys_user there is a field call “last_login”
See the script structure
var grUser = new GlideRecord('sys_user');
grUser.addQuery('active', true); // only active users
grUser.query();
var now = new GlideDateTime();
while (grUser.next()) {
if (grUser.last_login) { // check if the user has ever logged in
var lastLogin = new GlideDateTime(grUser.last_login);
var daysInactive = GlideDateTime.subtract(now, lastLogin).getNumericValue() / (1000 * 60 * 60 * 24); // convert ms to days
if (daysInactive >= 90) {
// your logic here
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2025 09:58 AM
don't forget to include following conditions:
- web service access only = false,
- internal integration user = false.
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
