- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2022 01:45 AM
Good morning,
I have a script include with a method in it which should return true/false if the user is logged in or not:
isUserLoggedIn: function(user){
return gs.getUser().getUserByID(user).isLoggedIn();
},
The function is returning undefined.
- The user sys_id is getting passed to the function correctly
- The getUserByID(user) seems to be getting a user 'com.glide.sys.User@*******'
- Script include is in Global, being called from Scoped app
Any ideas why this is returning undefined instead of true/false?
My aim is to check a specific user is logged in (why I have to getUserByID).
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2022 03:47 AM
Hi,
I believe the isLoggedIn() method runs only on getSession()
this table tells you the logged in users of the instance -> sys_user_session
If somebody logs out it removes record of that user from this table
use correct query as per your requirement
Regards
Ankur
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-07-2022 03:02 AM
The parameter is the sys_id of the user, yes.
I have tried with the sys_id too, but still returning false. The 'user' field on my instance is a string (not reference) and it has the user_name of the sys_user record, so that was why I was querying with this.
Even if I go to the v_user_session table as admin, I still cannot see the user logged in, because they are on a different node.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2022 03:12 AM
Hmm...now this is beyond me. Time to call the big guns.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2022 03:59 AM
Yes, this table only shows users logged in to the same node as you.
I'm not sure if what you want to do is easily achievable, which brings me to the next question - why do you need to do this in the first place?
Can you explain what problem this solves?
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2022 04:27 AM
Hi Paul, I have built some functionality in regards to moving incidents which are in the 'On Hold' state to a different assignment group (So it moves it out of the current assigned to/assignment group)
When that ticket goes back to in progress, I have a BR which will decide if the ticket goes back in to the original assigned to/assignment group queue, or an OVERFLOW queue for it to be assigned back out to someone else (Setting up to enable AWA).
When the user (previous assigned to) is offline, the ticket should go into the OVERFLOW queue. I have now resolved this by running my logic on the sys_user_session table instead, as suggested by
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2022 03:47 AM
Hi,
I believe the isLoggedIn() method runs only on getSession()
this table tells you the logged in users of the instance -> sys_user_session
If somebody logs out it removes record of that user from this table
use correct query as per your requirement
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader