Killing user session

Priyanka Palask
Tera Contributor

I want to kill user session which are active since last 60 minutes. 

Referring to below code snippet from various post and ServiceNow also sent this to me: 

 

var exclusionList=['integration_user','svc_account'];
var gr=new GlideRecord('sys_user_session');
gr.addQuery("sys_created_on<javascript&colon;gs.dateGenerate('"+sma+"')");
gr.addQuery('user.user_name','NOT IN', exclusionList);
gr.query();
 
But how can I check which user session is that, there is no "user" field on sys_user_session table. How we can apply second addQuery above to sort the session with user exclusions.
 
Appreciate your quick help
1 ACCEPTED SOLUTION

J Siva
Kilo Patron

Hi @Priyanka Palask 
You can use the 'name' field.

JSiva_0-1745296855023.png

 

var exclusionList=['integration_user','svc_account'];
var gr=new GlideRecord('sys_user_session');
gr.addQuery("sys_created_on<javascript&colon;gs.dateGenerate('"+sma+"')");
gr.addQuery('name','NOT IN', exclusionList);
gr.query();

Regards,
Siva

View solution in original post

6 REPLIES 6

Shree_G
Mega Sage

Hello @Priyanka Palask ,

 

To kill specific user session :

 

Go to "All-> User Administration -> Logged in users".

 

Shree_G_0-1745296578682.png

 

Here you will find all the logged in users and their transaction duration. Open the user record that you want to end and click "Lock out session".

Shree_G_1-1745296677985.png

 

This will end the session and the user will be re-directed to the login page. This will not lock the user, but only end the specific session.

J Siva
Kilo Patron

Hi @Priyanka Palask 
You can use the 'name' field.

JSiva_0-1745296855023.png

 

var exclusionList=['integration_user','svc_account'];
var gr=new GlideRecord('sys_user_session');
gr.addQuery("sys_created_on<javascript&colon;gs.dateGenerate('"+sma+"')");
gr.addQuery('name','NOT IN', exclusionList);
gr.query();

Regards,
Siva

Could you please help me understand why name is empty in user session table for so many records.

@Priyanka Palask I'm not sure. It could be created for non-interactive sessions, but I might be wrong.