How to identify all the currently logged in Users and having a valid session ID?

Rizwan Shaikh
Mega Guru

I am working on a requirement where I need to know if a user is currently logged into the system and has a valid session.

I know How to check for the currently logged in user. I want to know for a specific user.

  1. Lets say I have a X user and want to know he/she is currently logged into the system. How to achieve this?
  2. Also lets say I have a session ID. How to check if its still valid and not expired?

I have tried querying the "v_user_session_list" but it gives me only the current node users.

Any other way to know for overall users?

Help is much appreciated. Thanks!

 

 

1 ACCEPTED SOLUTION

Rizwan Shaikh
Mega Guru

Thanks guys, I was able to figure it out.

The table is sys_user_session table

Below URL will give you all the currently actively logged in User with a valid session ID

https://your_instance_name.service-now.com/sys_user_session_list.do?sysparm_query=nameISNOTEMPTY%5EinvalidatedISEMPTY%5Elast_accessedONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()%5Ename!%3Dguest%5EORname%3DNULL&sysparm_first_row=1&sysparm_view=

To cross verify the count use the below script.
var total_users = 0;
var diag = new Diagnostics();

while (diag.nextNode()) {
    var diagNode = diag.getNode();
    var ss = diagNode.stats.sessionsummary;

    if (ss) {
        gs.print(JSON.stringify(ss));
        total_users += parseInt(diagNode.stats.sessionsummary["@logged_in"]);
    }
}

gs.info(total_users);

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Are you saying this table "v_user_session" doesn't list all the users?

Anything specific you found that users from particular nodes are not captured in this table?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

Yes, The reason is there are 2 nodes for our instances. So It shows users on current node which I am logged in.

For more info please check this.

https://community.servicenow.com/community?id=community_question&sys_id=a47b8f21db9cdbc01dcaf3231f96...

Sulabh Garg
Mega Sage
Mega Sage

Hi Rizwan,

We have OOB Module, which gives all logged in users information with session Id details.

You may explore this option. Hope it helps.

 

find_real_file.png

 

 

find_real_file.png

Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

Hi Sulabh,

This lists only those users who are logged into the current node.

https://community.servicenow.com/community?id=community_question&sys_id=a47b8f21db9cdbc01dcaf3231f96...