Redirect /SP to Employee Center

Jon Collins2
Kilo Sage

Hi Folks, 

We've adopted the Employee Portal as out default portal, both for HR and IT users; however, we still have some users manually going to the old /sp service portal page - likely via bookmark, and we'd like to redirect them to the Employee Portal.

Has anyone else accomplished this?

Thanks

1 ACCEPTED SOLUTION

Loudigi
Kilo Sage

Hi Jon,

Yep, I had to redirect from 3 different portals to the new Employee Center. Basically, you'll add redirects from each portals theme via a JS include. @Mark Roethof did nice job of covering it here: https://community.servicenow.com/community?id=community_article&sys_id=9f1f869f1bf6f014aefc11751a4bcb69

Good luck!

View solution in original post

5 REPLIES 5

Mark A_ Miller
Mega Sage

One of my customers needed to temporarily redirect non-admin users from Employee Center to their Service Portal until implementation of Employee Center was complete. Solving this problem required some experimentation since documentation and solutions were lacking.

 

First I added a UI Script [sys_ui_script] related to the EC Theme (used by the Employee Center portal). The UI Script table is accessible via All > System UI > UI Scripts, then creating a new record. UI Type = Mobile / Service Portal.

 

MarkA_Miller_1-1708425720910.png

The UI Script record needed to be mapped to the Employee Center portal [sp_portal] and its related EC Theme [sp_theme]. This is accomplished by creating a JS Include [sp_js_include] record that references the UI Script, then creating a record on the JS Includes many-to-many table [m2m_sp_theme_js_include] that maps the new JS Include to the EC Theme.

 

JS Include:

MarkA_Miller_2-1708426064450.png

JS Includes M2M record (maps the UI Script / JS Include to the EC theme):

MarkA_Miller_3-1708426135588.png

With these mapping records in place and the new UI Script now related to the Employee Center portal, I was able to experiment with the client code and discover what information was contained in the global client objects. It turned out that 'this' was able to actually provide me with what I needed (whether the user has the admin role).

 

First I used alerts to print out the keys of the client object: 

var c = this;
var keys = Object.keys(c);
alert(keys);

Among the dozens of object keys printed out in the alert, I found the variable  

g_user_is_admin.

 

To determine whether this variable indeed stored a valid value for whether the current user is admin or not, I again used an alert to display the variable value:

alert(g_user_is_admin);

Impersonating a non-admin user and visiting <instance URL>/esc displayed the string "false". Viewing the same page as admin displayed the string "true".

 

Using this information I was able to redirect non-admin users to /sp by rewriting the UI script as

// Check if the current page's pathname starts with '/esc'
if (window.location.pathname.startsWith('/esc')) {
    // Check if the user is not an admin
    if (!g_user_is_admin) {
        // Redirect non-admin users to '/sp'
        window.location.href = '/sp';
    }
    // If the user is an admin, no action is taken, and they continue to '/esc'
}

This UI Script successfully allows an admin to proceed to Employee Center and redirects all others to Service Portal. When the customer was ready to make Employee Center available to their users, I simply deactivated the UI Script.