The CreatorCon Call for Content is officially open! Get started here.

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
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

SD4
Tera Contributor

Hi Mike,

 

 

can you show me the URL from which you are trying to fetch data

Jaspal Singh
Mega Patron
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);
    }
        }
    }