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.

Redirect users to new portal

Ace009
Tera Contributor

Id like to redirect any users without a specific role to a new portal. Ive set the default portal to the new portal. Ive tried modifying SPEntryPage.getFirstPageURL() to do a check for a specific role based on but it doesn't seem to run after a user has already logged in/started a session.

 

I referenced the following article:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0746730

 

So if a user is logged in already (and theyre in the new portal) but goes back to the old portal via a saved URL, they can do so. How can I prevent this?

1 ACCEPTED SOLUTION

James Chun
Kilo Patron

Hi @Ace009,

 

If you need to redirect the users to the new portal, you can write a UI Script,

e.g.

 

(function() {
    var loc = window.location;
    if (loc.pathname == '/esc') { //replace with your portal suffix
		alert('Redirecting to the new portal');
        var newUrl = loc.protocol + "//" + loc.host + "/yourportalsuffix" + loc.search + loc.hash;
        window.location.replace(newUrl);
    }

})();

 

 

And then add them as a JS Include in the Theme record of your old portal.

JamesChun_1-1717450588882.png

 

 

Cheers

View solution in original post

1 REPLY 1

James Chun
Kilo Patron

Hi @Ace009,

 

If you need to redirect the users to the new portal, you can write a UI Script,

e.g.

 

(function() {
    var loc = window.location;
    if (loc.pathname == '/esc') { //replace with your portal suffix
		alert('Redirecting to the new portal');
        var newUrl = loc.protocol + "//" + loc.host + "/yourportalsuffix" + loc.search + loc.hash;
        window.location.replace(newUrl);
    }

})();

 

 

And then add them as a JS Include in the Theme record of your old portal.

JamesChun_1-1717450588882.png

 

 

Cheers