How to redirect users in ServiceNow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 04:46 PM
Hello,
I have a requirement to redirect users to different pages when the login. Currently this is not done through SSO, but Okta maybe used in the future. We are working with the Customer Service Management Plugin
I have a couple of cases
1) Contacts and Consumers logging in should be redirected to the "csm" portal
2) Agents should be redirected to Agent Workspace, but may need to navigate to UI16
3) Duty Managers and Admins should be redirected to UI16
My current solution involved adding the following lines of code to the getFirstPageURL function of the SPEntryPage script includes.
if(gs.hasRole('admin')|| gs.hasRole('u_back_end_viewer')){
return;
}
if(gs.hasRole('itil')){
return '/now/workspace/agent/home';
}
if(gs.hasRole('snc_external') && redirectURL){
return "/csm";
}
The role u_back_end_viewer has been created to give to duty managers and admins so that they're properly redirected.
This solution works, mostly, however under case (2) Agents can't navigate to UI16, even when using "/nav_to.do?uri=%2Fhome.do%3F" as it instead brings them back to the Agent Workspace. They can however navigate to the customer service portal using /csm.
I am looking for a modification that will handle redirection ONLY when the user logs in, so that Agents can still access UI16 through a different URL or provided link
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 07:34 PM
Hello
I am not sure whether you are aware of that Script Include "SPEntryPage" is for Service Portals only. You write something about login but you forgot to mention which kind of login do you mean: login on a Service Portal page or the standard instance login.
Then looking at your code it is working exactly that way you described.
if(gs.hasRole('itil')){
return '/now/workspace/agent/home';
}
That if block will redirect a itil user to the workspace without having any choice.
If you don't want that behaviour should modify the above if condition.
And last there is an article about redirecting users at Service Portal login. Maybe it helps: https://pathwayscg.com/service-portal-auto-redirect/
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 07:47 PM
Hello Maik,
Thanks for looking into this.
Currently for testing I'm logging in through /login.do for my various test users, and I am being redirected as I had hoped/expected.
The issue comes when I try to navigate away from the Agent Workspace as an Agent (by changing the URL) as navigation to the "/csm" portal works, but not "/nav_to.do?uri=%2Fhome.do%3F"
My understanding is that the script should run at login to redirect the user (which is what I want) but should not run when I am already logged in and trying to access other parts of the system. Is my understanding of the script incorrect, and it runs more frequently than simply at login? Or does accessing UI16 go through another login step when navigating from Agent Workspace that I am unaware of?
"forgot to mention which kind of login do you mean: login on a Service Portal page or the standard instance login" - I had intentionally left this out, as I wanted it to run regardless of login method. If this is causing my error, how could I change/fix this to make it work better?
Thanks again
Felix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 09:07 PM
Hi
I have set the two system properties which are mentioned Script Include "SPEntryPage".
Then after logging out I was redirected to the login page of the Service Portal just as expected.
Then I opened the Workspace and redirected manually to "../nav_to.do?uri=%2Fhome.do%3F".
Now the Script Debugger waked up, because I have set a breakpoint and startet a debug session.
From that point you can run and debug your code in the Script Debugger to understand how your additional code influences the redirection flow.
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2021 10:41 AM
Hi
Did my reply answer your question?
If so, please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
If not, please tell me what you are still missing.
Many thanks and kind regards
Maik