Instance URL via JavaScript
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2014 08:52 AM
I usually only use this code to create links within comments or e-mail notifications:
var html = '<a href="/nav_to.do?uri=' + current.getTableName() + '.do?sys_id=' + current.sys_id + '" target="blank">' + current.number + '</a>';
Are there any script include functions that I can call to get the instance URL to create the FQDN?
For example, clicking this link via an e-mail while a user is not logged on will give a 404 error.
If the comment resides in a dev instance I would want the URL to be: https://instancedev.servicenow.com/[URL HERE]
If the comment resides in a production instance I would want the URL to be: https://instance.servicenow.com[URL HERE]
Is there any way to call the DNS or FQDN via javascript? At least with the FQDN, I can parse it and trim it to what I need...
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2014 09:11 AM
You can get your instance's URL using:
gs.getProperty('glide.servlet.uri')
The full link would look like:
var html = '<a title="tProperty('glide.servlet.uri') + 'nav_to.do?uri=' + current.getTableName() + '.do?sys_id=' + current.sys_id + '" href="' + gs.getProperty('glide.servlet.uri') + 'nav_to.do?uri=' + current.getTableName() + '.do?sys_id=' + current.sys_id + '" target="blank">' + current.number + '</a>';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2014 09:22 AM
Thanks for the quick reply but running a quick log statement via Background Script on any of our three instances returns the production instance:
gs.log('BG Script - Servlet URI: ' + gs.getProperty('glide.servlet.uri'));
Returns:
*** Script: BG Script - Servlet URI: https://instance.service-now.com/
Even though I was on instancedev.service-now.com or even instancepprd.service-now.com the log statement returned instance.service-now.com.
Is there any way to distinguish the instances via script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2014 09:35 AM
Yes, you could use the property: instance_name
However: Both properties only work if their value was adjusted.
I would simply adjust the value of both properties to reflect your instance name. Do this for all your instances and by simply referencing these properties you can write scripts which will always return the correct instance name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2014 10:34 AM
I believe that will work. I checked the properties and they are, in fact, different. Thank you!