How to check user is logged in or not.

niveditakumari
Mega Sage

Hello, 

How to check user is logged in or not. 

ex - when user receives an email and in that user receives some link and after clicking on that link it should check whether user is logged in or not if yes then it should redirect user to particular service now page else it should redirect user to login page. 

Can anyone please help me with this. 

 

Regards, 

Nivedita 

1 ACCEPTED SOLUTION

Hi Nivedita,

 

First i would suggest you to not paste the complete url as you did in your previous since it is taking to your customer Prod instance and anyone can able to order the catalog request. Please try to remove it or at least remove the instance name from the link

 

Coming to your issue, i use you are using  "com.glideapp.servicecatalog_cat_item_view" in your URL which is a UI Page first try to see if this ui page is granted as public for goto ui page and search with the name and if you dont find anyting there goto sys_public table and search in the page field if it is available try to inactive and see if it works. 

 

Next if you dont find anything there go to that catalog item which is "Solicitud Extensión Guad" and look for the field role and see if is public you can remove and try again.

 

Basically if the ui page or catalog item are set as public which means any user outside servicenow can access that particular page/cat item. if you find that i think you can solve your issue.

 

Please go through below link where it clearly explain how to make the catalog item as public you just need to follow the steps and and if you find anything try to remove and inactive and try again.

 

https://hi.service-now.com/kb_view.do?sysparm_article=KB0551300

 

 

Note: Please try in Sandbox or Developer instance first before trying to implement in Prod instance.

 

 

If my reply was helpful / resolved your issue please mark it as correct / helpful

Regards,

Abdul Azeez

 

 

 

View solution in original post

18 REPLIES 18

Megha Padale
Giga Guru

Hi Nivedita,

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 in 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 

If my answer helped you in any way, mark answer as helpful and correct.

Thanks and regards,

Megha.

Thanks and regards,

Megha.

DirkRedeker
Mega Sage

Hi

This happens automatically. If you sent a URL for (e.g.) some record inside your instance, and the user is NOT logged in, ServiceNow will automatically sent him/her to the login page.

Otherwise, the record will be displayed automatically.

Does that make sense for your question?

BR

Dirk

Yes..but because of some issue it is not working in this way..it was redirecting user to catalog item page even user was not logged in.

Swapnil Soni1
Giga Guru

Hi,

There is an OOB module for this:

 

 

 

logged in users.PNG

 

You can glide this table (v_user_session) where you get the logging user.And then you can put the condition like user is logged in then use current.setRedirectURL('put what you want to open') and in else condition you can redirect user to login page.

For Login page you can refer this link might be helpful for you

https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/script/server-scripting/task/t_...

 

Mark helpful or correct if this helps.

Thanks

Swapnil