Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Keyboard shortcut to logout of Employee Portal

Joel Bowles
Tera Contributor

Does there exist or is there a way to setup, a keyboard shortcut to logout of the Employee Portal?

 

Thanks

1 ACCEPTED SOLUTION

Robert H
Mega Sage

Hello @Joel Bowles ,

 

You can do this as follows:

 

1) Create a UI Script

Name: EC Logout keyboard shortcut

UI Type: All

Script: paste the following code, and adjust the condition for the desired key combination as needed

document.addEventListener('keydown', e => {
    // check for key combination ALT + SHIFT + L
    if (e.code === 'KeyL' && e.altKey && e.shiftKey) {
        window.location.href = '/logout.do?sysparm_goto_url=/esc';
    }
});

 

2) In the Theme record for Employee Center ("EC Theme" by default), create a new JS Include that refers to the above UI Script

RobertH_0-1744355467606.png

 

If you now open Employee Center and press ALT + SHIFT + L you will be logged out of ServiceNow.

 

Regards,

Robert

View solution in original post

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@Joel Bowles ServiceNow does not provide a native keyboard shortcut to log out of the Employee Portal.

Robert H
Mega Sage

Hello @Joel Bowles ,

 

You can do this as follows:

 

1) Create a UI Script

Name: EC Logout keyboard shortcut

UI Type: All

Script: paste the following code, and adjust the condition for the desired key combination as needed

document.addEventListener('keydown', e => {
    // check for key combination ALT + SHIFT + L
    if (e.code === 'KeyL' && e.altKey && e.shiftKey) {
        window.location.href = '/logout.do?sysparm_goto_url=/esc';
    }
});

 

2) In the Theme record for Employee Center ("EC Theme" by default), create a new JS Include that refers to the above UI Script

RobertH_0-1744355467606.png

 

If you now open Employee Center and press ALT + SHIFT + L you will be logged out of ServiceNow.

 

Regards,

Robert

Thanks Robert!  For whatever reason that script didn't seem to work, but after modifying it slightly this worked:

(function() {

    document.addEventListener('keydown', function(e) {

        if (e.altKey && e.shiftKey && e.code === 'KeyL') {

            window.location.href = '/logout.do';

 

        }

    });

})();

Hello @Joel Bowles ,

 

Thank you for the feedback. I did some reading and found that the "keyCode" property that I used in my code is marked as obsolete, so maybe that's the reason why it did not work for you. I have updated the code in my earlier response to use the "code" property instead, just like you did.

 

Regards,

Robert