Want to force custom URL instead of service-now.com URL

Randall King
Tera Expert

We have used ServiceNow's custom URL feature to create a custom URL for our instance, so instead of https://myschool.service-now.com, we can use https://servicenow.myschool.edu. However, ServiceNow doesn't force that URL, so users can still opt to use the default one. We would like to force the custom URL by redirecting users to our custom domain name for the instance.

 

We have made this work with a UI script for the custom URLs that we have for our service portals, but for whatever reason it doesn't work for the regular platform UI. I'm pasting what we are using below. I was hoping that I can get help on what I'm doing wrong.

 

if(window.location.hostname.indexOf("service-now.com") >-1)
{	
			var curr_url = window.location;
			var curr_url_str = curr_url.toString();
			if(curr_url_str.indexOf("myinstance.service-now.com") > -1)
			{
		
				var m = curr_url_str.replace("myschool.service-now.com","servicenow.myschool.edu");
				top.location = m;
			}
			else if(curr_url_str.indexOf("myschooldev.service-now.com") > -1)
			{
		
				m = curr_url_str.replace("myschooldev.service-now.com","dev.servicenow.myschool.edu");
				top.location = m;
			}
			else if(curr_url_str.indexOf("myschooltest.service-now.com") > -1)
			{
		
				m = curr_url_str.replace("myschooltest.service-now.com","test.servicenow.myschool.edu");
				top.location = m;
			}
}

 

Additionally, the script is configured with "UI Type" set to "All", though we have tried "Desktop" and got the same negative results. The "Application" is "Global", and I made sure that the script is enabled.

1 REPLY 1

mkrishnasundar
Giga Expert

Your code seems fine, except the first line where you do check window object. Window obj is rendered only in portal UI not in native UI. For native UI, you may need to use "top.window". Read the below article to understand the difference between the usage of window obj in portal vs native UI. Hope that will solve your issue.

https://www.servicenow.com/community/developer-articles/top-window-document-objects-in-native-ui-and...

 

Regards,
Krishna
https://www.linkedin.com/in/mkrishnasundar/