Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Redirection on Portal

india
Tera Guru

Dear Experts,

My requirement is if the user has MX_PORTAL role then he should be redirected to "sp_blau" and if not then "sp"
So I did changes in the SP Entry page scriptRedirection is working fine, but when the user manually changes the URL to https://devXXXX.service-now.com/sp then he is able to see the sp portal which I do not want.

 

I also wrote this UI Script and added it to JS to include it on the theme record of the/sp portal but in the console I am getting this error "Uncaught Reference Error: addLoadEvent is not defined"Here is my ui script

addLoadEvent(redirect);
function redirect() {
	if(g_user.hasRoleExactly("MX_PORTAL") && document.URL.indexOf('sp_blau')== -1){
		window.location='/sp_blau';
	}
	else
	{return;}
}



1 ACCEPTED SOLUTION

india
Tera Guru

To help everyone 
Steps :
1. create a UI script and from that ui script call script include via glideAjax,
2. then based on the response from that script include you can redirect.

View solution in original post

6 REPLIES 6

Tony Chatfield1
Kilo Patron

Hi, for UI script I have been using this syntax

addLoadEvent(function() {
//do something
});

I also used that but same error
addLoadEvent(function() {
if(g_user.hasRoleExactly("MX_PORTAL") && document.URL.indexOf('sp_blau')== -1){
window.location='/sp_blau';
}
else
{return;}
});

Harish KM
Kilo Patron
Kilo Patron

Hello can you try the below

addLoadEvent(function()
{
if(g_user.hasRoleExactly("MX_PORTAL") && document.URL.indexOf('sp_blau')== -1){
window.location='/sp_blau';
}
else
{return;}

});

Regards
Harish

Yes I tried that also