Finding the Name or URL of your Instance via Script

Here’s a quick tip that shows you how to retrieve the name or URL of your Service-now instance. This can come in handy if you need to construct a URL in a business rule or mail script or if you have some automated post-clone configuration when dealing with multiple Service-now instances in your environment.

Each instance has a property stored in the ‘sys_properties’ (System Properties) table that stores the name of your instance. The name of the property is (unsurprisingly) ‘instance_name’. You can find the value of this property via any server-side script (Business Rules, etc.) by using the ‘gs.getProperty’ method like this…

var instanceName = gs.getProperty('instance_name');

If you need to get the full URL for your instance you can get it from the ‘glide.servlet.uri’ property the same way…

var instanceURL = gs.getProperty('glide.servlet.uri');

Here’s a useful function that I’ve seen used before to create an html link for a specific record. All you need to do is pass in the table name and sys_id of the record and the function returns the html.

function CreateLinkForObject(strTableName, strSysID){
   return "<a href=\" + gs.getProperty('glide.servlet.uri') + gs.generateURL(strTableName, strSysID) + ">LINK</a>";

Date Posted:

January 26, 2010

Share This:


  1. ND May 17, 2012 at 8:44 am

    Hi Mark,

    This is very useful information.

    I am looking for similar method to find URL of a site created by us. We have created a site with prefix Booking, now I want to find the site using command so that I can create different welcome page for this site.

    I tried using above method for site, but it is not working as it will return the instance not the actual URL.


    • Mark Stanger May 17, 2012 at 9:00 am

      That’s correct. This returns instance URLs. I don’t have an equivalent currently that handles CMS site URLs.

    • Jim Coyne May 18, 2012 at 7:47 pm

      I’m not sure exactly what you are looking for, but can you use “window.location” in your script to get the URL of the page you are on and then check the value of that string???

Comments are closed.




Fresh Content
Direct to Your Inbox

Just add your email and hit subscribe to stay informed.