When the user logs in, if it takes too long to redirect, inform a message at the top to wait

Elton2
Tera Contributor

Hi everyone, good afternoon!

When the user logs in to access the Portal, sometimes it is very slow to perform the redirection to the home screen, would you be able to tell me if there is any way to include a message, such as: gs.InfoMessage(‘Please wait, you will be redirected!’)?

 

Obs.: this message will appear after a setTimeOut, is it possible?

 

HTML:

<div>

        <div class="form-group">
          <label for="username" class="">{{::data.usernameMsg}}</label>
          <input id="username" name="username" autocapitalize="off" ng-keypress="c.message = ''" ng-click="c.message = ''" class="form-control no-border input-advanced" type="text" placeholder='{{::data.usernameMsg}}' autofocus="true" ng-model="c.username"/>
        </div>
        <div class="form-group">
          <label for="password" class="">{{::data.passwordMsg}}</label>
          <input id="password" name="password" ng-keypress="c.message = ''" ng-click="c.message = ''" class="form-control no-border input-advanced" type="password" placeholder='{{::data.passwordMsg}}' ng-model="c.password"/>
        </div>
 
              <button name="login" type="submit" ng-click="c.login_in()"class="btn btn-lg btn-primary btn-block login-button-old">
                ${Login}
              </button>
 
</div>
 
 
CLIENT SCRIPT:
c.login_in = function(){
setTimeout(function() {
            location.reload(true);
        }, 100)
gs.addInfoMessage("Please wait, you will be redirected!");
}
 
Can anybody supporte me?
Tks
1 ACCEPTED SOLUTION

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Elton2 ,

 

It seems like you want to display a message while the user is being redirected to the home screen after logging in to the ServiceNow portal. Your approach with the client script is on the right track, but there are a couple of things to consider for a smoother user experience.

First, it's important to note that adding a brief delay using setTimeout to simulate a message might not be the most reliable way to achieve this. Also, using location.reload(true) to refresh the page right after logging in might not be necessary and could potentially cause some unexpected behaviors.

Instead, you can use AngularJS to manage the message and redirect more effectively. Here's how you can modify your code to achieve this:

 

<div>
  <!-- Other form elements -->

  <!-- Message element -->
  <div ng-show="c.displayMessage" class="info-message">
    {{ c.messageText }}
  </div>

  <button name="login" type="submit" ng-click="c.login_in()" class="btn btn-lg btn-primary btn-block login-button-old">
    ${Login}
  </button>
</div>

 

Client: 

 

c.login_in = function() {
  // Show the message
  c.displayMessage = true;
  c.messageText = "Please wait, you will be redirected!";

  // Delay for a moment (e.g., 1 second)
  setTimeout(function() {
    // Navigate to the home screen (assuming '/home' is the correct URL)
    window.location.href = '/home';
  }, 1000); // Adjust the delay as needed
};

 

In this , the message will be displayed using the ng-show directive, and after a brief delay, the user will be redirected to the home screen using window.location.href.

Remember to adjust the delay time in the setTimeout function based on your preference.

Please mark helpful if my answer satisfies your requirement. 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

View solution in original post

4 REPLIES 4

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Elton2 ,

 

It seems like you want to display a message while the user is being redirected to the home screen after logging in to the ServiceNow portal. Your approach with the client script is on the right track, but there are a couple of things to consider for a smoother user experience.

First, it's important to note that adding a brief delay using setTimeout to simulate a message might not be the most reliable way to achieve this. Also, using location.reload(true) to refresh the page right after logging in might not be necessary and could potentially cause some unexpected behaviors.

Instead, you can use AngularJS to manage the message and redirect more effectively. Here's how you can modify your code to achieve this:

 

<div>
  <!-- Other form elements -->

  <!-- Message element -->
  <div ng-show="c.displayMessage" class="info-message">
    {{ c.messageText }}
  </div>

  <button name="login" type="submit" ng-click="c.login_in()" class="btn btn-lg btn-primary btn-block login-button-old">
    ${Login}
  </button>
</div>

 

Client: 

 

c.login_in = function() {
  // Show the message
  c.displayMessage = true;
  c.messageText = "Please wait, you will be redirected!";

  // Delay for a moment (e.g., 1 second)
  setTimeout(function() {
    // Navigate to the home screen (assuming '/home' is the correct URL)
    window.location.href = '/home';
  }, 1000); // Adjust the delay as needed
};

 

In this , the message will be displayed using the ng-show directive, and after a brief delay, the user will be redirected to the home screen using window.location.href.

Remember to adjust the delay time in the setTimeout function based on your preference.

Please mark helpful if my answer satisfies your requirement. 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Hi @Sohithanjan G 

Tks for your support, Im gonna see it.

Tks again!!!

Hi @Elton2 ,

If you got it, could you please accept the solution :). Click on Mark as Accept Solution Button

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Hi @Sohithanjan G , how are you?!

Ok

Tks again