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.

Getting the URL from Server Script

cspra
Giga Expert

Hello,

Is there a way to capture the URL/URI in Server Script of a widget in the INITIAL load of the page?

*location, *window, getUrlOnStack are either returning null or undefined.

getGlideURI() - is returning not exactly the URI from the URL address. The '=', '&' are converted to different format such as '%3d', '%26'.

Thanks.

 

   

5 REPLIES 5

vinothkumar
Tera Guru

You can get the instance URL by getting the below property.

 

var instanceURL = gs.getProperty('glide.servlet.uri');

Thanks Vino but that only returns the static portion of URL.  I want to capture the part after that.

Hi,

please try this in server side script

var url = gs.action.getGlideURI().toString();

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

cspra
Giga Expert

I ended up using getGlideURI() [my 2nd option] but added decodeURIComponent() to get rid of symbol transformation.

decodeURIComponent(gs.action.getGlideURI());

Thanks for looking into this.