- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2020 05:46 AM
Would anyone be able to assist me with creating a mechanism to disable users that have not logged in for 30 days? We are not using an external SSO or User Management system. I am guessing that a business rule would be used to accomplish this? Thanks for your help!
Solved! Go to Solution.
- Labels:
-
Instance Configuration

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2020 05:57 AM
you can create scheduled job with below script and run it daily
var Days = gs.daysAgoStart(30).split(' ');
var gr = new GlideRecord('sys_user');
gr.addQuery('last_login', 'CONTAINS', Days[0]);
gr.addActiveQuery();
gr.query();
while (gr.next()) {
gr.active = false;
gr.update();
}
or
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('last_login<javascript:gs.beginningOfLast30Days()');
gr.addActiveQuery();
gr.query();
while (gr.next()) {
gr.active = false;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2020 05:56 AM
Hello, I'd suggest creating a scheduled job, that checks the 'last login' field on 'sys_user' table (in case it's populated).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2020 05:57 AM
you can create scheduled job with below script and run it daily
var Days = gs.daysAgoStart(30).split(' ');
var gr = new GlideRecord('sys_user');
gr.addQuery('last_login', 'CONTAINS', Days[0]);
gr.addActiveQuery();
gr.query();
while (gr.next()) {
gr.active = false;
gr.update();
}
or
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('last_login<javascript:gs.beginningOfLast30Days()');
gr.addActiveQuery();
gr.query();
while (gr.next()) {
gr.active = false;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2020 07:53 AM
Thanks for the assist!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2021 05:23 PM
Hi
Can you help me ?
1) I need to automate the activation of an inactive user from the user's login. I would like to deactivate an account when the user was unused for 90 days, but when he needs to use it again, I need to activate it without intervention in the administration of the tool. It's possible ?
Do you have an example of this type of event to be triggered and the script I need to create to activate users ? In which module does it have to be implemented?
2) I have a problem managing disabled users. When disabled they no longer receive notifications and emails about approvals and notifications. Being disabled, it is not possible to generate the approval task and the process is interrupted. Can I work around this situation so that they receive some notification (email) or as soon as they become active again, receive approvals and pending notifications?
Thanks for you help.