Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

About the behavior of "URLSearchParams"

bonsai
Mega Sage

I'm developing a portal screen that I intend to display in the platform's content frame.

I tried to get the URL using "var urlParams = new URLSearchParams(decodeURIComponent(top.location.search));" in the catalog client script, but nothing was retrieved.

The portal screen works fine if I display it in a separate tab instead of the content frame.

Is there any difference in behavior?

<Example of displaying a portal screen in the platform content frame>

bonsai_0-1771457848483.png


<Normal portal screen>

bonsai_1-1771457914855.png

 

 

6 REPLIES 6

Santhana Rajhan
Mega Sage

To get the ServiceNow platform URL from a content frame (iFrame), you need to access the top-level window from within the frame. This is necessary because the content frame is often inside nav_to.do, which hides the base instance URL

 

// Get the base URL (e.g., https://instance.service-now.com)
var platformURL = window.top.location.origin;

// Alternative to get full URL including relative path
var fullUrl = window.top.location.href;

// or just
var URL = window.top.location;

 

Are you trying Catalog Client script?

Both will result in an error if used in a catalog client script.

Ankur Bawiskar
Tera Patron

@bonsai 

what's your actual business requirement?

Why would you want to see portal within native?

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

The idea is to create records on the catalog item screen on the portal screen,
and then view the records created on the platform screen from a list.

We considered implementing everything on the portal, but currently we plan to use both the portal and the platform.

For that reason, we came up with the idea of ​​pasting the portal URL into the module and displaying it in the content frame.