We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to retrieve info from URL through client script on load?

Mike S3
Giga Expert

I would like get the view name from the URL through a catalog script , I have the current script but I'm getting the following error message : 

TypeError: Cannot read properties of null (reading 'URL')

 

function onLoad() {

    var view = getParm('view');
	
    if (view.toString() == 'review2') {
		
         g_form.setValue('u_earb_request_type','review2');  
	  g_form.setReadOnly('u_request_name',false);
	   g_form.setReadOnly('u_assigned_lead',false);
	   g_form.setReadOnly('u_client_name',false);
    }


}

function getParm(value) {
    var url = document.URL.parseQuery();
    if (url[value]) {
        return decodeURI(url[value]);
    } else {
        return;
    }
}
1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron

Can you try below code as is in your onLoad script once.

 function getParameterValue(name) {
        var url = top.location.href;
        var value = new URLSearchParams(url).get(name);
        if (value) {
            return value;
        }
        if (!value) {
            var gUrl = new GlideURL();
            gUrl.setFromCurrent();
            value = gUrl.getParam("view");
            return value; //this will give you the value


       if (value.toString() == 'review2') {
		
         g_form.setValue('u_earb_request_type','review2');  
	  g_form.setReadOnly('u_request_name',false);
	   g_form.setReadOnly('u_assigned_lead',false);
	   g_form.setReadOnly('u_client_name',false);
    }
        }
    }

View solution in original post

6 REPLIES 6

Anjaneyulu Muv1
Tera Expert

hi,

 

Please refer this link

https://community.servicenow.com/community?id=community_question&sys_id=955ffdb3db1e6340656a5583ca96194f

I tried this , but got the following error message : 

 

ReferenceError: GlideURL is not defined

SD4
Tera Contributor

Hi Mike,

 

function onLoad() {

 

  var url = window.location.toString();

 

  var parms = url.toQueryParams();

 

  if (parms["view"] == "review2") {

 

g_form.setValue('u_earb_request_type','review2');

g_form.setReadOnly('u_request_name',false); 

g_form.setReadOnly('u_assigned_lead',false);

g_form.setReadOnly('u_client_name',false);

 

  }

 

}

 

 

 

Hope this helps!

Thanks for the response SD , but I got an error message with your script : 

 

find_real_file.png