How to get instance URL in UI Action client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2019 08:26 PM
Hi experts:
I am writing script in UI Action client script.
I want the URL domain in my script.
I have tried "window.location.host", but browser displayed "Cannot read property 'location' of null".
However, if I enter "window.location.host" in browser console, this command works.
Anyone could help?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2019 08:48 PM
Hi,
Can you try the following and see if it works for you?
var url = window.parent.location.href;
alert(url);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2019 09:19 PM
Hi Phoenix,
window object won't work in scoped app
try this
var url = this.location.href;
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2023 07:55 AM
@Ankur Bawiskar That was amazing. I actually used this.location.origin because I wanted the "https" included.
Question: What does the *this* object represent in the context of a portal Catalog Client Script? Where is this documented, please? Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2023 07:21 PM
most of the things we usually use are undocumented and we get to know about those from community, blogs etc
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader