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

Thanks, this is just what I needed, but one problem: if there are spaces in my field value, I get HTML code for them.  So that "this is a short description" becomes "this%20is%20a%20short%20description".

I guess I could use the javascript Replace function, but is there a simpler way?

EDIT: never mind, DecodeURI() did the trick.

Rj27
Mega Guru

I am trying to load portal page from a ui page. This page is nothing but a record producer
I am able to to that.
Suppose my url that coming on portal is :https://<INSTANCE>.service-now.com/portal?id=sp_home&sysparm_prjType=<prjType>&sysparm_created_by=<user id>'

I want to give a check if sysparm_prjType has some value then the a field on item should be auto checked as true on load.

For this i have added a onload client script in my record producer. 
Tried both ways but none of them is working. When the portal is loaded, its giving error..


1)

function onLoad() {
    var prj= getParameterValue('sysparm_prjType');
if (prj) {
}
}

function getParameterValue(name) {
var url = document.URL.parseQuery();
if (url[name]) {
alert(url[name]);
alert(decodeURI(url[name]));
return decodeURI(url[name]);
} else {
return;
}    
}

//this is not working

 

2)

var gUrl = new GlideURL();
gUrl.setFromCurrent();
var prj= gUrl.getParam("sysparm_prjType");
alert('prj'+prj);

//ERROR MESSAGE :  ReferenceError: GlideURL is not defined

 

My ui type is set to Mobile/Service portal on client script 

and I have enabled isolate script to true.

CAn someone help me on this what could be the reason ?