Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Unable to get the parameter value from URL

Rakesh50
Mega Sage

We are trying to get the value from URL by using onload catalog client script but we couldn't.

URL : https://test.service-now.com/nav_to.do?uri=%2Fu_cx_catalog_picker.do%3Fsysparm_parent_anchor%3Dhttps:%2F%2Ftest.service-now.com%2Finteraction.do%253Fsysparm_record_list%253DORDERBYDESCnumber%2526sysparm_record_rows%253D29%2526sysparm_record_row%253D8%2526sysparm_record_target%253Dinteraction%2526sys_id%253D0ae8bcc71bafc1d8c8e7db9ebd4bcb06%26sysparm_parent_number%3DIMS0000028%26sysparm_parent_sys_id%3D0ae8bcc71bafc1d8c8e7db9ebd4bcb06%26sysparm_parent_table%3Dinteraction

From above URL we need sysparm_parent_sys_id parameter value. We tried below script please check and let us know if any corrections 

function onLoad() {
//Type appropriate comment here, and begin script below
var InteractionSysID = getParameterValue('sysparm_parent_sys_id');

alert(InteractionSysID);
if(InteractionSysID !='')
g_form.setValue('interaction',InteractionSysID);
function getParameterValue(name) {
var url = top.location.href;
var value = new URLSearchParams(url).get(name);
if (value) {
return value;
}
}
}

In alert we are getting null value

7 REPLIES 7

not worked

Hi @Chetan Mahajan 

Tried but showing below error

find_real_file.png

Jaspal Singh
Mega Patron
Mega Patron

Try below.

function onLoad() {
	
	var v_sURLParam = "";
	v_sURLParam = "sysparm_parent_sys_id";
	
	
	var v_sID = getParameterValue(v_sURLParam);
	if (v_sID) {
		g_form.setValue('interaction', v_sID);
	}
	
}

function getParameterValue(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(top.location);
	if (results == null) {
		return "";
	} else {
		return unescape(results[1]);
	}
}