How to check if user is logged in?

Kristoffer Mon1
Giga Expert

I'm working on a Slack integration where the person who submitted the request is notified when comments are added to a task. (Comments on the Task are "bubbled" up to the RITM and REQ)

Since I don't want send a Slack notification for every comment added, I was thinking about checking to see if the requestor is already logged in; of which I will not send a Slack notification.

I've tried impersonation of the requestor in Dev to to check if to see if my methods are correct in detecting if the user is logged in, but it only generates a session under the my account.

1 ACCEPTED SOLUTION

John Heal, thanks for chiming in.

Since I created a business rule that triggers when a comment is added, I needed to know if the "requestor" was logged in, when the "assigned_to" person added a task comment. So using isLoggedIn() would not help if needed to know if the "requestor" was logged into ServiceNow, when the business rule was running under the context of the assigned_to.

 

I ended up checking if the requestor had a valid session. Seems to work; haven't gotten any complaints about users receiving too many Slack notifications.

View solution in original post

5 REPLIES 5

John Heal
Giga Contributor

The function for checking if a users is logged in is

isLoggedIn()

Determines if the current user is currently logged in.

Return:
TypeDescription
BooleanTrue if the current user is logged in, false otherwise.
Scoped equivalent:

To use the isLoggedIn() method in a scoped application, use the corresponding scoped method: isLoggedIn().

If you are querying how you check this in dev would any of the following work i your instance

  • Set up a dummy user and run your check against that user.
  • Run the check by passing in your own logged in user.
  • Ask a colleague to log in with their account and pass them into your function
  • Run your code through background script and pass in a user you know is logged in

 

Please mark as answered if the above helps.

 

John Heal, thanks for chiming in.

Since I created a business rule that triggers when a comment is added, I needed to know if the "requestor" was logged in, when the "assigned_to" person added a task comment. So using isLoggedIn() would not help if needed to know if the "requestor" was logged into ServiceNow, when the business rule was running under the context of the assigned_to.

 

I ended up checking if the requestor had a valid session. Seems to work; haven't gotten any complaints about users receiving too many Slack notifications.

Hi,

could you please share, how you checked if requester had valid session. I have a requirement where I am getting a session id of user and I am suppose to check if its valid. 

Hi Kristoffer,

Could you please guide us how to check if a specific user has a valid session ID?

Thanks!