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

adamjgreenberg
ServiceNow Employee
ServiceNow Employee

This is handled by the sys_user_token and sys_user_session.


Scenario 1 - The user receives a link and their session has timed out. The user will be required to log in and then will be directed to the link.

Scenario 2 - The user receives a link and their session is active. The user will be directed to the link.

Thank you for your reply. 

Scenario 1 - User is getting email notification to extend his account validity and user is not logged in, so user should be redirected to login page. 

I need to implement above functionality that if user is not logged in and user clicks on link then it should redirect to login page. 

Can you please suggest me some steps that how can i achieve this. 

 

Regards, 

Nivedita 

 

AbdulAzeez
Mega Guru

Hi @niveditakumari 

 

Servicenow has a method called isLoggedIn(), which is useful to determine whether the user is currently logged in. It will return true if the user is logged in or else return false if the user is not logged in or if the session has timed out.

 

gs.isLoggedIn(); //return true if the user is logged in 

 

When user clicks the link will that takes servicenow page intially as an inbound action ? if yes, then in the inbound action you validate wheather user is currently logged in or not

 

if ( gs.isLoggedIn() ) { 
//Your code 


} 

 

 

Please mark helpful or correct based on the impact.

Regards,

Abdul Azeez

Thank you for your reply. 

When user clicks the link it takes servicenow page intially as an inbound action or not..i am not sure for this..can you please suggest me how to check. 

 

Regards, 

Nivedita