Redirect (inactivate) Service Portal, e.g. from /s... - ServiceNow Community
Mark Roethof
Tera Patron
Tera Patron

Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

The method described in this article became obsolete with the introduction of "Deactivate a portal and optionally redirect to another portal" in the Xanadu release.

 

Hi there,

 

Out-of-the-box, ServiceNow Instances are shipped with nine different Service Portals. Maybe you've added some additional plugins which increase this number or created a custom Service Portal. What if you would like to deactivate some of these Service Portals? As some are specifically targeted for end-users, while you are only using one or two of those Service Portals for end-users? For example because you have a /sp, /hr, /csm, and you are switching over to Employee Center (/esc).

Unfortunately, deactivating a Service Portal is not possible. There's not something like an active flag. So what can we do?


Delete?

As mentioned, deactivating a Service Portal is not possible. Theoretically you could delete a Service Portal. I haven't seen any best practices on this, though personally I wouldn't go for this option.
- What if for whatever reason you want to go back to that Service Portal or you need a specific part of that Service Portal?
- When it concerns an out-of-the-box Service Portal, changes might be done during Hot Fixes, Patches, or Upgrades. These will be added or will cause Skipped Updates.


Page Route Maps?

Deactivating a Service Portal is not possible, deleting a Service Portal is not a good go-to. What about redirecting, would that be possible? Out-of-the-box, there is the option "Page Route Maps". With this for example, you can redirect your HR ticket pages to the Standard Ticket page in Portal. This option is page-specific, so it does not redirect your Service Portal itself.

 

There's no other configuration that helps you redirecting within Service Portal. Redirecting when a user opens /sp or /sp?id=sc_home, having the user redirected to /esc for example.


JS Include!

Redirecting is possible though with a small workaround! You could add a JS Includes on a Theme record that is associated with the specific Service Portal you want to redirect. JS Includes will be loaded on attempt to display every URL. Within the JS Includes record, you can create a UI Script which makes redirection possible using the JavaScript object window.location.


Service Portals > Theme

Open the Theme associated with the Service Portal concerned.

 

find_real_file.png


Theme > JS Includes

Add a new JS Includes record on the Related List at the bottom of the Theme record.

 

find_real_file.png


JS Include > UI Script

Add a new UI Script record on the JS Include record.

 

find_real_file.png


UI Script

Set the UI Type to "All" and add the scripting concerned.

 

(function () {

    window.location.assign("/esc");

})();

 

find_real_file.png


Result

When a user opens the /sp Service Portal, almost instantly the user is redirected to the Employee Center (/esc).

---


And that's it. Hope you like it. If any questions or remarks, let me know!

 

C

If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.

 

Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in?
- Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Kind regards,


Mark Roethof

ServiceNow Technical Platform Architect @ Quint Technology

2x ServiceNow Developer MVP

2x ServiceNow Community MVP

---

LinkedIn

Comments
Maik Skoddow
Tera Patron
Tera Patron

Interesting approach!

What if the redirecting should be condition based? For example, only redirect users with the role "snc_external" (end users).

Kind regards
Maik

Mark Roethof
Tera Patron
Tera Patron

Sounds like should be possible. Haven't tried yet. Was focussing now for a project on redirecting for example /sp > /esc and /sp?id=sc_cat_item&sys_id=249833602fccf010cd5dd99df699b664 > /esc?id=sc_cat_item&sys_id=249833602fccf010cd5dd99df699b664

Will share the second one asap.

Kind regards,
Mark

Mark Roethof
Tera Patron
Tera Patron

The answer is yes, is possible also. You can perform GlideAjax for example with which you should be able to achieve this. I will be sharing an example using this approach in the future.

Kind regards,
Mark

Sriraj V
Tera Contributor

Hi Mark & Maik , @Mark Roethof @Maik Skoddow 

I have the same question, how to redirect end users to /esc instead of /sp..? Any thoughts on this? 

As you both aware, for redirecting end users to /sp : I have created a property "glide.entry.first.page.script" and used this "new SPEntryPage().getFirstPageURL()".

 

Regards,

Sriraj

 

Sriraj V
Tera Contributor

Hi Mark @Mark Roethof ,

Can you elabarote more, I would like to try this for redirecting only end users to /esc instead of /sp.

Regards,

Sriraj

Mark Roethof
Tera Patron
Tera Patron

What do you need to elaborate more? Which part is unclear for you from the article?

Kind regards,
Mark

Daniel Wang
Tera Contributor

Hi Mark,

Regarding Maik's question about role based conditional redirect, you mentioned using GlideAjax, could you please eleborate more on that? 

Thought the reason why GlideAjax, might be because cannot use gs.hasRole with UI script, so I checked if the employee has alumin role on the backend and send the result to the UI script. I have attached my UI Script along with the Script Includes. Currently, they are not working. Look forward to your reply, thanks!

DanielWang_0-1677110093238.png

DanielWang_1-1677110142851.png

 

 

Daniel Wang
Tera Contributor

Hi 

Just to answer my own question: how to make role-based portal redirect, the tested and worked UI script & Ajax are posted here:

 

Use case: when Alumni logins, portal restricts user to Alumni Service Center

DanielWang_5-1680124784045.png

 

Use GlideAjax to determine the role of the current login user on the backend and send the decision to the frontend.

In Line 6, the logic will determine if the script triggers. If the employee already in the asc, they don’t need to be redirected.

DanielWang_6-1680124784050.png

 

Application scope should correspond to the one for the UI script (in this case Employee Center Core)

Line 5, gs.hasRole includes admin, so need to account for that (not sure if need to put !gs.hasRole(“admin”) on both sides of the OR statement, correct me if wrong).

DanielWang_7-1680124784055.png

 

Script Includes’ ACL requires the roles based on which portal redirects (not sure needed but just to be safe)

 

Please mark this helpful for encouragements 🙂

Community Alums
Not applicable

This was helpful.   I modified the UI Script a little to intercept any link with the /sp in it to redirect to the /esc portal.  Seems to working.

(function () {
    var path = window.location;
    var newpath = path.toString().replace("/sp","/esc");
    alert(newpath);
    window.location.assign(newpath);

})();

 

JamesAcevedo88
Tera Contributor

Can this solution work if I want to redirect all users that are not admin from the /esc to the login.do page?

Version history
Last update:
‎08-03-2024 07:05 AM
Updated by:
Contributors