instanceName, instanceURL and HTML link link to a record

PHOTO EMBED

Tue Mar 15 2022 21:22:40 GMT+0000 (Coordinated Universal Time)

Saved by @RajanMurkute

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>";
}
content_copyCOPY