- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 09:22 PM
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:
Solved! Go to Solution.
- Labels:
-
Architect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 09:41 PM
Hi @Priyanka Palask
You can use the 'name' field.
var exclusionList=['integration_user','svc_account'];
var gr=new GlideRecord('sys_user_session');
gr.addQuery("sys_created_on<javascript:gs.dateGenerate('"+sma+"')");
gr.addQuery('name','NOT IN', exclusionList);
gr.query();
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 09:53 PM - edited 04-21-2025 09:54 PM
the name field on table "sys_user_session" holds username
Also you can't delete the record from this table as deleting doesn't help here.
you need to set locked field on table "v_user_session" to true so kill session
So please enhance the script for that table "v_user_session"
Something like this but please enhance
var gr = new GlideRecord('v_user_session');
// give proper query if you want using addQuery or addEncodedQuery
if (gr.get('user', 'username_of_user_to_kill')) { // Replace username_of_user_to_kill with the user's username
gr.locked = true;
gr.update();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2025 08:12 AM
Did you get a chance to check my above response?
Deleting records from "sys_user_session" won't help.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader