- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
How to get the instance URL using the OnLoad Client Script of the Form?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
this will work
var url = top.location.href;
alert(url);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Hi @KeDix ,
it depends on browsers sometimes!,
Are you trying to get the instance URL or the current opened URL?
If its for the Instance URL - why don't you try script include and use the system property as below
Client script:
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('GetInstanceUrl');
ga.addParam('sysparm_name', 'getUrl');
ga.getXMLAnswer(response);
function response(url){
alert(url);
}
}
Script include:
var GetInstanceUrl = Class.create();
GetInstanceUrl.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getUrl: function(){
return gs.getProperty('glide.servlet.uri');
},
type: 'GetInstanceUrl'
});
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Here is the solution:
Get the Instance URL without using Script Include:
var instanceURL = top.location.href; get full URL
instanceURL = instanceURL.slice(0, instanceURL.indexOf("/now")); // Instance URLg_form.addErrorMessage(htmlMessage);
g_form.addDecoration('field_name','icon-alert',"No relation",'color-red');
g_form.addDecoration('field_name','icon-locked',"No relation",'color-red');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
this will work
var url = top.location.href;
alert(url);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
This gave the complete URL instead of the instance URL. But how can I make it a clickable link under the field using
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
you can't show link in field message as it's not supported in showFieldMsg()
if you want instance URL then no direct way available
1) either use Display business rule + g_scratchpad in onLoad
OR
2) onLoad with GlideAjax
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Thank you for marking my response as helpful.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
