URL field question

akillius
Kilo Expert

Hopefully this is an easy one for someone.   I added a URL field to my form for users to put specific web addresses (e.g, www.google.com).   When they click on the URL, it is appending our instance name before the address (e.g, https://instancename.service-now.com/google.com).   How do I prevent the instance name from appending?

 

Thanks,

Andy

1 ACCEPTED SOLUTION

tltoulson
Kilo Sage

Hi Andrew,



From a similar question I recently answered: URL Field Type



When typing the URL into the field, "http://" or "https://" should be included before the URL.   If you leave off the protocol, the url is treated as relative to the instance url.   If you include the protocol, the url is treated as an absolute URL. So the url entered should read "http://www.google.com"


The requirement for the protocol prepended to the url is a HTML specification implemented by browsers themselves, so there is no way around that.



Within ServiceNow you could add a client script and/or business rule to check the url field for http:// and add it if it is not present.   This would remove the requirement for users to include it themselves.   For example:



Client Script



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


      if (isLoading || newValue == '') {


                  return;


      }


      if ((newValue + '').indexOf('http://') == -1) {


                  g_form.setValue('url', 'http://' + newValue);


      }


}



Business Rule (before)



(function() {


      if ((current.url + '').indexOf('http://') == -1) {


                  current.url = 'http://' + current.url;


      }


})();


View solution in original post

8 REPLIES 8

Ya Pradeep, I know. Never faced this issue before, so I was thinking Andrew can give this a try just in case


Yes but unfortunately that will not help here



Thanks,


Pradeep


rsanon
Tera Contributor

Hi Andrew!



Were you able to resolve this?


tltoulson
Kilo Sage

Hi Andrew,



From a similar question I recently answered: URL Field Type



When typing the URL into the field, "http://" or "https://" should be included before the URL.   If you leave off the protocol, the url is treated as relative to the instance url.   If you include the protocol, the url is treated as an absolute URL. So the url entered should read "http://www.google.com"


The requirement for the protocol prepended to the url is a HTML specification implemented by browsers themselves, so there is no way around that.



Within ServiceNow you could add a client script and/or business rule to check the url field for http:// and add it if it is not present.   This would remove the requirement for users to include it themselves.   For example:



Client Script



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


      if (isLoading || newValue == '') {


                  return;


      }


      if ((newValue + '').indexOf('http://') == -1) {


                  g_form.setValue('url', 'http://' + newValue);


      }


}



Business Rule (before)



(function() {


      if ((current.url + '').indexOf('http://') == -1) {


                  current.url = 'http://' + current.url;


      }


})();