Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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?

6 REPLIES 6

Well, I sure wish I knew what * this * referred to, so I could best utilize all it's magical properties...

ValorPhase
Tera Contributor

The answer suggesting to use "this.location.origin" didn't work for me in 2025, so I had to use this instead:

g_GlideUI.topWindow.location.origin

 The g_GlideUI.topWindow should get you access to the "window" and all its tasty goodness that SN has munged to prevent us from doing so...  😉