Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Trying to parse parameters from a url to client script on a catalog item

archanachil
Tera Contributor

Hi ,

 

We are using an ui action with with we are sending the parameter via URL to a client script on a catalog item.

 

though the url is having parameters but the cilent is not picking it up .

for reference providing the script below.

please help with any suggestions you have!

 

function onLoad() {
    alert("hi 1");
  var metrixValue = g_form.getParameter('sysparm_metricValue');
alert("hi 2");
  if (metrixValue) {
    alert("hi 3");
    g_form.setValue('request_summary_2', metrixValue); // Replace 'request_summary_2' with the correct variable name
  }
}    
 
 
OR
 
 
function onLoad() {
alert("Hi");
   var ABC1 = getParmVal('sysparm_metricValue');
   alert("HI2");
   var ABC2 = getParmVal('sysparm_metricValue2');
   if(ABC1){
    alert("Hi3");
      g_form.setValue('request_summary_2',ABC1);
   }
   if(ABC2){
      g_form.setValue('cio_action_comments_2',ABC2);
   }
}

function getParmVal(name){
    var url = document.URL.parseQuery();
    if(url[name]){
        return decodeURI(url[name]);
    }
    else{
        return;
    }
}
 
we tried various ways , didn't workout can anyone let us know you thoughts on this!!
 
Thanks in advance!
1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @archanachil ,

If you have the parameters in your URL, you can use this logic to fetch them. I've used it in one of my project and it works.

 

 var gUrl = top.location.href; //get the URL
//fetch the parameter, add the correct name of your parameter instead of parameter_name1.
    var name1 = new URLSearchParams(gUrl).get("parameter_name1"); 

                                

 

 

Thanks,

Hope it helps.

If my response turns useful, you can mark it helpful and accept solution.

View solution in original post

2 REPLIES 2

Community Alums
Not applicable

Hi @archanachil ,

If you have the parameters in your URL, you can use this logic to fetch them. I've used it in one of my project and it works.

 

 var gUrl = top.location.href; //get the URL
//fetch the parameter, add the correct name of your parameter instead of parameter_name1.
    var name1 = new URLSearchParams(gUrl).get("parameter_name1"); 

                                

 

 

Thanks,

Hope it helps.

If my response turns useful, you can mark it helpful and accept solution.

archanachil
Tera Contributor

Thanks @Community Alums