How do you read URL from Catalog Client Script

marclindsay
Tera Guru

I have created a UI Action that runs server side and redirects a user to a Record Producer. The UI Action adds data to the URL (UI Action Redirect : com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=21378b88db9e2300c218d740cf961961&sysparm_comments=testing passing information). Within the Catalog Client Script I am trying to read the URL to get the parameter needed for defaulting some of the fields on the Record Producer screen.

Everything I have read looks like I should be able to do the following to get my data out of the URL. document.URL.parseQuery();  This command is not working. I keep getting the error 'Cannot read property 'URL' of null'.

Stuck as to how I get my information out of the URL

1 ACCEPTED SOLUTION

Ok, Can you try this once.

var gUrl = new GlideURL();
gUrl.setFromCurrent();
var comments = gUrl.getParam("sysparm_comments");
g_form.setValue('description', comments);

 

View solution in original post

16 REPLIES 16

What is the difference between GlideURL() and using 'document' ? 

Is one better than the other? In case I would be in a situation where both solutions would be working for me?

document.URL is the legacy Javascript method using in the web based systems 

https://www.w3schools.com/jsref/prop_doc_url.asp

GlideURL() is a SN specific API used for the same purpose and i bet that this is better than the legacy one as it avoids the direct DOM manipulation.

Hey Ali, 

I did a bit of experimentation. GlideURL() on a client script fails for a record on Portal / Workspace. At least until the Madrid release. I was trying to get a CS to run on a targeted view, say, 'Service Portal' *view=sp*. Works on the platform UI no probs. But, this API has at least this one gap that SN may plug in a future release. 

Cheers. 

Jai

Hi Jai,

It seems GlideURL is not supported in the portal framework. There is an alternative GlideURI API for scoped apps but that doesnt work either.

Guess we need to go with the legacy JS objects.

top.location.href returns the URL in both platform and portal and works for both scoped and global apps. Not a neat one though! 

Thanks!

Super helpful Ali, thanks!