document.URL.parseQuery() suggestion to replace

Jim J1
Tera Guru

We are getting tagged in Health Check for var url = document.URL.parseQuery(); as DOM manipulation issue. Looking for suggestions to replace 'var url = document.URL.parseQuery();' in client script

2 REPLIES 2

justin_drysdale
Mega Guru

A user answered a similar question here:


Re: How to get entire URL in Client Script OR sysparm



Here is a deep dive:


https://www.servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script...



IMO, using DOM to snag the url will always be supported but I understand the need to be in full compliance.


I have created a catalog client script to grab the URL parameters on a catalog item coming from NEW CALL.  I have written the client script the same way the OOB client script "Propose a new Standard Change Template" is written but I cannot get the parameters out of the URL.

 

Here's my client script:

I've also tried it without trying to get two parameters (just the Requested For)

Any ideas why this doesn't work but the Standard Change Template client script does?  Only difference I can find is the Change Template is a Record Producer, not a Catalog Item.

 

Here's my URL:

/nav_to.do?uri=%2Fcom.glideapp.servicecatalog_cat_item_view.do%3Fsysparm_id%3D0f3534a4db29b7007f24e415ca9619fb%26sysparm_reqFor%3D3df0f1c11bc0fb00b2eea60d2d4bcb5d%26sysparm_location%3D%26sysparm_details%3DNEW_CALL_REF%253ACALL0004731%2Blkjljlkj%26sysparm_stack%3Dnew_call.do%3Fsys_id%3Dfd77669adb2dbb00171cfd333996195c%26sysparm_stack%3Dnew_call_list.do%3Fsysparm_query%3Dactive%3Dtrue%26sysparm_contact_type%3Dphone

 

function onLoad() {	
	var reqFor = getParmVal2('sysparm_reqFor');
	var details = getParmVal2('sysparm_details');
		
	if (reqFor){
		g_form.setValue('variables.requested_for', reqFor);
	}
		
	if (details){
		if (g_form.getControl('description'))
		g_form.setValue('description', details);
	}
}


function getParmVal2(name){
	var url2 = document.URL.parseQuery();
        alert("URLName=" + url[name]);
	if(url2[name]){
		//We never get here
		return decodeURI(url2[name]);
	}
	else{
		return;
	}
}