ARG645
Tera Guru

Please hit Like or Bookmark this article if it helps.

 

Use Case 1: Log out all users who are currently logged into ServiceNow before an outage. Usually we communicate to all the users about the outage days before the actual Outage start date. But just to make sure no one is currently logged into the instance during the outage, we can run the below background script few minutes before the actual outage start time.

var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery('active=true^locked_out=false^user_name!='+gs.getUserName());
userGr.query();

while(userGr.next()){
  var userName = userGr.getValue('user_name');
  GlideSessions.lockOutSessionsInAllNodes(userName);
}

Output:

locked_out user abel.tutor
locked_out user julio.curry
locked_out user sergio.chang
locked_out user ramon.amaral
locked_out user Howard.Lewis
......
.....
....
...
..
.

 

Use Case 2: Annoy a friendly co-worker by logging them out

var userName = 'your coworkers user name';
GlideSessions.lockOutSessionsInAllNodes(userName);

 

Thank you,

Aman Gurram

ServiceNow Systems Integration Specialist

Helpful links:

Force Logout Users in all Nodes

How to Logout all the user that are currently logged In from the Instance 

Comments
Siva74
Tera Contributor

Hi,

Is there a way to achieve this without being redirected to logout page.

I am trying to inactivate user session in ServiceNow based on an event in external application, but ServiceNow page gets redirected to logout page.


Thanks,
Sivaranjani S

Sunny24
ServiceNow Employee
ServiceNow Employee

Hello, is there a way to do this by logging out a loggedin user once they are added to a group?

rajkumar5
Tera Contributor

Hi,
Can you try with these possiblities.

1) location.href='logout.do';

 

2) openFrameAPI.openCustomURL('logout.do');

Version history
Last update:
‎07-05-2020 08:37 PM
Updated by: