Display custom message to user in Service Portal login page when account is locked out

Community Alums
Not applicable

I have customized installation exit to modify the error message for failed login attempt. It is working as expected in the main console, but service portal login still displays old message.

Main console:

find_real_file.png

Service Portal:

find_real_file.png

I have verified that the new installation exit is invoked for service portal login, but message is incorrect. I would like to display different messages based on account locked_out status. Please assist.

1 ACCEPTED SOLUTION

Community Alums
Not applicable

I was able to fix the issue by adding custom code to server script:

if(input.flag == "true") {
var gr = new GlideRecord("sys_user");
gr.addQuery('user_name', input.username);
gr.query();

if(gr.next()) {
if(gr.locked_out) {
data.customMsg = gs.getMessage("crt_account_locked");
//input.username = '';
}
else {
data.customMsg = gs.getMessage("login_invalid");
}
}
else {
data.customMsg = gs.getMessage("login_invalid");
}
return;
}

Modified the client script as per the screenshot shared by Naveen, but with little more customization:

else {
// wrong username or password
/*c.message = response.data.message;
c.password = "";
c.username = "";*/
c.data.flag = "true";
c.server.update().then(function() {
c.message = c.data.customMsg;
c.password = "";
c.data.username = "";
});
angular.element("#username").focus();
}

 

Finally add .data to ng-model of username in HTML: ng-model="c.data.username"

View solution in original post

8 REPLIES 8

Naveen20
ServiceNow Employee
ServiceNow Employee

You have to modify the login widget as shown in attachment below.

Community Alums
Not applicable

I would like to display messages based on locked out state. Any idea how that can be accomplished?

The same message comes up even when the account is locked out. No separate  message is coming from the api.

Community Alums
Not applicable

I was able to fix the issue by adding custom code to server script:

if(input.flag == "true") {
var gr = new GlideRecord("sys_user");
gr.addQuery('user_name', input.username);
gr.query();

if(gr.next()) {
if(gr.locked_out) {
data.customMsg = gs.getMessage("crt_account_locked");
//input.username = '';
}
else {
data.customMsg = gs.getMessage("login_invalid");
}
}
else {
data.customMsg = gs.getMessage("login_invalid");
}
return;
}

Modified the client script as per the screenshot shared by Naveen, but with little more customization:

else {
// wrong username or password
/*c.message = response.data.message;
c.password = "";
c.username = "";*/
c.data.flag = "true";
c.server.update().then(function() {
c.message = c.data.customMsg;
c.password = "";
c.data.username = "";
});
angular.element("#username").focus();
}

 

Finally add .data to ng-model of username in HTML: ng-model="c.data.username"