How to get instance URL in UI Action client script?

PhoenixMing0912
Giga Expert

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?

5 REPLIES 5

Alikutty A
Tera Sage

Hi,

Can you try the following and see if it works for you?

var url = window.parent.location.href;

alert(url);

 

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@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!

@G24 

most of the things we usually use are undocumented and we get to know about those from community, blogs etc

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader