UI Script for portal redirect based on role not working

Garrett2
Tera Expert

I have this UI script

 

(function() {

var isInternal = g_user.hasRole('snc_internal', true);
if(!isInternal) {

var loc = window.location;
//var oldUrl = loc.protocol + "//" + loc.host + loc.pathname + loc.search + loc.hash;
var newUrl = loc.protocol + "//" + loc.host + "/kc" + loc.search + loc.hash;
window.location.replace(newUrl);
}
})();

 it's attached to a theme for my service portal. I would like to redirect users who land on that portal to the /kc portal.

 

(function() {
var loc = window.location;
//var oldUrl = loc.protocol + "//" + loc.host + loc.pathname + loc.search + loc.hash;
var newUrl = loc.protocol + "//" + loc.host + "/kc" + loc.search + loc.hash;
window.location.replace(newUrl);
})();

 This version works with no issues. It's not until I add the conditional statement that I run into issues. Any idea on why that isn't working?

1 REPLY 1

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Garrett2 ,

Can you please check below articles and threads. Might be helpful :-

6 ways to set up your Service Portal for redirection SUCCESS! 

Issue while redirecting to service portal based on roles 

UI Script for portal redirect based on role not working 

Service Portal - Redirect via UI Script 

Redirect users to different pages based on roles 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy