Redirecting Users to Login Page After Account Lockout in ServiceNow

Puneet Hegde1
Tera Guru

I am trying to redirect users to the login page (/login.do) when their account gets locked due to too many failed login attempts. I've implemented the following script in a Business Rule that triggers after a failed login:

if (gr.failed_attempts > 4) {
gr.locked_out = true;
gr.update();
gs.log("User " + gr.user_name + " locked out due to too many invalid login attempts");
gs.addErrorMessage("Your account has been locked due to too many failed login attempts. Please contact the support team at XXXXXXXXX@XXX.com");

// Redirect users to the login page
var response = gs.getSession().getResponse();
response.setStatus(303); // HTTP status for redirection
response.sendRedirect("/login.do"); // Redirect to login page
}

However, the redirection doesn't seem to work, and users are not being redirected to the login page as expected. Instead, the error message is displayed, and the page stays on the current view.

What I've Tried:

  1. Verified that /login.do is the correct URL.
  2. Used gs.addErrorMessage to notify users of the lockout.
  3. Cleared cache (/cache.do) and tested the changes again.
  4. Experimented with both g_response and gs.getSession().getResponse() for redirection.

Environment:

  • Running in a Scripted Event triggered on login failure.



1 ACCEPTED SOLUTION

Puneet Hegde1
Tera Guru

I was able to achived the required work with the simple by logging out the user using 'gs.setRedirect('/logout.do');'
it help me to auto redirect to login page based on the portal users are using. 

View solution in original post

2 REPLIES 2

Paul Curwen
Giga Sage

Take a look at Script Include SPEntryPage which controls redirects etc. 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

Puneet Hegde1
Tera Guru

I was able to achived the required work with the simple by logging out the user using 'gs.setRedirect('/logout.do');'
it help me to auto redirect to login page based on the portal users are using.