- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 09:05 PM
Hi,
The user tries to log in and types the wrong password several times then the user account is locked.
We need to unlock those user accounts automatically after 1 or 2 days if the user is active in the snow.
Regards,
Abdul
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 09:22 PM
Hello
Write a scheduled runs with runs daily and set a specific time. then use the below code:-
var gr = new GlideRecord("sys_user");
gr.addQuery("active", "true");
gr.addQuery("locked_out", "true");
gr.query();
while (gr.next()) {
gr.locked_out=false;
gr.update();
}
Please mark answer correct/helpful based on Impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 09:17 PM
You can write a scheduled job to do this .
Run a scheduled job daily or periodically which checks for locked out and active user accounts based on last bad password attempt field .
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 09:22 PM
Hello
Write a scheduled runs with runs daily and set a specific time. then use the below code:-
var gr = new GlideRecord("sys_user");
gr.addQuery("active", "true");
gr.addQuery("locked_out", "true");
gr.query();
while (gr.next()) {
gr.locked_out=false;
gr.update();
}
Please mark answer correct/helpful based on Impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 11:06 PM
Hello,
There is a similar OOTB functionality. Please check this link: Specify lockout for failed login attempts | ServiceNow Docs. It lets you define a time period after which the account will get unlocked automatically, but only if the account was locked out due to failed login attempts.
If this does not meet your requirements, you need to create scheduled job as the other members have commented above.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 07:12 AM
Going along with Annay, the specific System Policy => Events => Script Action you would look for is "SNC User Lockout Check with Auto Unlock".
Convert the 1 or 2 days (depending on your decision) to minutes. Then update the first line within "triggerUnlock" function (line getting the glide.user.unlock_timeout_in_mins property).
function triggerUnlock(userSysID) {
var unlockIn = gs.getProperty("glide.user.unlock_timeout_in_mins", 15);
var trigger = new GlideRecord("sys_trigger");
trigger.name = "Unlock the user after "+ unlockIn + " mins";
trigger.next_action = getTriggerTime(unlockIn);
trigger.job_id.setDisplayValue('RunScriptJob');
trigger.script = getTriggerScript(userSysID, gs.nowNoTZ());
trigger.document = 'sys_user';
trigger.document_key = userSysID;
trigger.state = 0;
trigger.trigger_type = 0;
trigger.insert();
}