THURSDAY, FEBRUARY 09, 2012

Finding the Name or URL of your Instance via Script

H

ere’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>";
}
Tags:  

Leave a Reply


Notify me of followup comments via e-mail. You can also subscribe without commenting.

Latest Comments

  • Aric: Finally figured out what I was doing wrong, incase someone else wants to do this. Mark is correct about needing...
  • Mark Stanger: You’ll probably need at least 3 total ACLs then. You’ll need one...
  • Mark Stanger: Hey Paul, I assume you’re talking about ‘task_ci’, not ‘task_group. If so, the...
  • ND: Hi Mark, This is cool. How can I do same at the form level. I have created a slushbucket variable and I want to...