Get Current URL in UI Builder Client Script

Stefan Uzunov
Tera Contributor

Hey, everyone.

Trying to find out how to get the current URL in Client Script created in UI Builder. It seems I have no access to 'window' object. Any other alternatives? 

1 ACCEPTED SOLUTION

Yeah you should be able to grab a parameter from the url and use it for the src url on the iframe. Unfortunately there's not a great way for the contents of the iframe to communicate back with the UIB page using the oob component. You could build a custom iframe component that would do that, though.

View solution in original post

5 REPLIES 5

Brad Tilton
ServiceNow Employee
ServiceNow Employee

What exactly are you looking to do here? You can't grab the entire url, but you can pull in url parameters via api.context.props.<urlparmname>.

Hey, Brad
Thank you for your quick response! I want to build the 'source' field of an IFrame component to point to a url in the instance(the url is outside the UI Builder). I thought that I will need to pass the scheme and domain name(https://myInstance.service-now.com), but it seems I can just pass a relative url, and it works.  

To confirm, though - is this the correct approach?

@Brad Tilton , on a related note - how do I make the IFrame communicate with the rest of the UI Builder page if I do not have access to 'window' object?

Yeah you should be able to grab a parameter from the url and use it for the src url on the iframe. Unfortunately there's not a great way for the contents of the iframe to communicate back with the UIB page using the oob component. You could build a custom iframe component that would do that, though.