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.

Get URL value in client script

Rj27
Mega Guru

Hi,

I am trying to load portal page from a ui page. This page is a record producer.
I am able to to that (loading portal page).
Suppose my url that coming on portal is :https://<INSTANCE>.service-now.com/portal?id=sp_home&sysparm_product_sysid=<product sys id>

I want to give a check if sysparm_product_sysid has some value then the a field on item should be auto checked as true on load.

For this i have added a onload client script in my record producer. 

My ui type is set to Mobile/Service portal on client script .

and I have enabled isolate script to true.


Tried both ways but none of them is working. When the portal is loaded, its giving error..

1. 

   var prdID = getParmVal('sysparm_product_sysid');
   if(prdID){
      alert('prd');
	   //g_form.addInfoMessage('prd'); 
   }
}

function getParmVal(name){
    var url = document.URL.parseQuery();
    if(url[name]){
		alert('inside function');
        return decodeURI(url[name]);
    }
    else{
        return;
    }
	

 

Error:
find_real_file.png

 

2.

var gUrl = new GlideURL();
gUrl.setFromCurrent();
var prdID= gUrl.getParam("sysparm_product_sysid");
alert('prdID  '+prdID);

Error message:
find_real_file.png


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

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

7 REPLIES 7

Maik Skoddow
Tera Patron
Tera Patron

Hi

on client side there is a OOTB object g_uri you can use.

In the following page all methods are listet: https://community.servicenow.com/community?id=community_question&sys_id=d960d729dbdcdbc01dcaf3231f96...

Maik

Hello Maik,

Will this work client side ?

I tried this..

var uri = g_uri.action();
var fileString = uri.get('sysparm_product_sysid');
g_form.addInfoMessage('fileString  '+fileString);

 

Error:
ReferenceError: g_uri is not defined

JACQ1
Tera Expert

Hi, try using top.location.href

 

Thank you

 

This Works!