how to route users to employee center based on specific user criteria
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2025 06:24 AM
Hi,
We need to route all users who report to a specific person to employee center portal when they try to access ServiceNow. Can anyone assist on how to achieve this requirement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2025 06:37 AM
Do you want to redirect user based on role?
Please refer to the following article this might be helpfull for you:
https://www.servicenow.com/community/developer-articles/role-based-redirection-with-spentrypage/ta-p...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2025 06:39 AM
Hi @sath,
To achieve this, you should modify the SPEntryPage Script Include, which is the standard method for controlling portal redirection. In the getFirstPageURL function of this script, add a condition to check if the currently logged-in user's manager is the specific person you've identified. You can get the user's manager with gs.getUser().getManagerID(). If the manager's sys_id matches your target, set the redirect URL to the Employee Center portal suffix (e.g., /esc). This ensures that only the direct reports of that specific manager are automatically routed to the correct portal upon accessing ServiceNow.
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wednesday - last edited Wednesday
Hi @M Iftikhar @Medi C @Nehal Dhuri
I have setup the redirection of users to employee center based on cost center and not having itil role. It is not working. Can someone please assist?
/**
*
* Service Portal sample script include to indicate
* 1. which login page should be used
* 2. the starting page after the user is authenticated
*
* Script is configured using system properties
* PROPERTY VALUE
* glide.entry.page.script new SPEntryPage().getLoginURL();
* glide.entry.first.page.script new SPEntryPage().getFirstPageURL();
*
* functions can return a path or null if no overrides are necessary
*
**/
var SPEntryPage = Class.create();
SPEntryPage.prototype = {
initialize: function() {
this.logVariables = false; // for debugging
this.portal = "/sp/"; // The URL suffix specified in the sp_portal record
this.empCenter = "/esc"; // The URL suffix specified in the employee center record
},
/***
*
* Referred to by property: glide.entry.page.script
*
**/
getLoginURL: function() {
// When requesting a page directly (eg: /problem_list.do)
// The platform session_timeout.do sets the login page to welcome.do
// Since we are handling the login, clear that value
var session = gs.getSession();
var nt = session.getProperty("nav_to");
var sPage = session.getProperty("starting_page");
if (nt == "welcome.do")
session.clearProperty("nav_to");
if (!sPage && !nt)
session.putProperty("starting_page", gs.getProperty("glide.login.home"));
// Send the user to the portal's login page
var portalGR = new GlideRecord("sp_portal");
portalGR.addQuery("url_suffix", this.portal.replace(/\//g, ""));
portalGR.addNotNullQuery("login_page");
portalGR.query();
if (portalGR.next())
return this.portal + "?id=" + portalGR.login_page.id;
// Send to the a default login page
return this.portal + "?id=login";
},
/***
*
* Referred to by property: glide.entry.first.page.script
*
**/
getFirstPageURL: function() {
var session = gs.getSession();
this.logProperties('before', session);
// has roles and is not a Service Portal page - go to UI16
var nt = session.getProperty("nav_to");
var isServicePortalURL = new GlideSPScriptable().isServicePortalURL(nt);
var redirectURL = session.getProperty("login_redirect");
if (user.isMemberOf('IT-Support')) {
return;
}
if (user.hasRole('itil') || user.hasRole('admin') || user.hasRole('itil_audit')) {
//allow admin and itil users access to the backend
return;
}
//Custom logic to route users to Employee Center
if (user.cost_center.code == '10000') && !user.hasRole('itil')) {
return this.empCenter;
}
// user may have logged in from a frame, the /login_redirect.do page will bust out of it
if (!redirectURL) {
// redirectURL is nav_to
// if nav_to == "welcome.do" then use starting_page
var sPage = session.getProperty("starting_page");
if (sPage && nt == "welcome.do")
nt = sPage;
// Avoid a redirect loop to the home page
var ep = gs.getProperty("glide.login.home");
if (nt) {
if (ep == nt)
nt = null;
}
// PRB726860: if page is still welcome.do, go to glide.login.home preserving frameset
if (nt == "welcome.do") {
session.putProperty("nav_to", ep);
return;
}
session.putProperty("login_redirect", nt || "true");
return "/login_redirect.do?sysparm_stack=no";
}
session.clearProperty("login_redirect");
session.clearProperty("nav_to");
var returnUrl = this.portal;
if (redirectURL && redirectURL != "true") {
var spUrl = new GlideSPScriptable().mapUrlToSPUrl(redirectURL);
returnUrl = spUrl ? this.portal + "?" + spUrl : redirectURL;
}
this.logProperties('after', session);
if (!this.logVariables) {
gs.log('redirectURL: ' + redirectURL);
gs.log('User: ' + user.getName());
gs.log('is internal: ' + (!user.hasRoles()));
gs.log('returnUrl: ' + returnUrl);
}
return returnUrl;
},
logProperties: function(beforeOrAfter, session) {
if (!this.logVariables)
return;
gs.log('SPEntryPage: Redirect ------------------------------- ' + beforeOrAfter);
gs.log('session.starting_page: ' + session.getProperty("starting_page"));
gs.log('session.nav_to: ' + session.getProperty("nav_to"));
gs.log('session.login_redirect: ' + session.getProperty("login_redirect"));
gs.log('gs.fURI: ' + session.getURI());
},
type: 'SPEntryPage'
};
The only change made to the existing script is to add custom logic for employee center.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday - last edited Thursday
Hi @sath,
I’ve tested your script in my PDI using a user assigned with cost_center.code:10000 and only the snc_internal role (without the itil role), and the redirection is working as expected.
Could you please verify that the following system properties have been created correctly in your instance?
Name: glide.entry.first.page.script
Type: String
Value: new global.SPEntryPage().getFirstPageURL();Name: glide.entry.page.script
Type: String
Value: new global.SPEntryPage().getLoginURL();
Let me know if these are set up correctly on your end, and we can troubleshoot further if needed.
If my response helped, please mark it as the accepted solution so others can benefit as well.
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.