gs.getUser().getUserByID(user).isLoggedIn(); not working in script include

Cris P
Tera Guru

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).

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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

find_real_file.png

Regards
Ankur

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

View solution in original post

10 REPLIES 10

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.

Hmm...now this is beyond me. Time to call the big guns.

@Ankur Bawiskar @Mark Roethof @Sandeep Dutta 

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

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 @Ankur Bawiskar 

Ankur Bawiskar
Tera Patron
Tera Patron

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

find_real_file.png

Regards
Ankur

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