Solution - How to Get browser URL parameters in client script

SANDEEP28
Mega Sage

Hi All,

 

I have seen multiple community posts about getting browser URL parameter in client script. However in most of the posts, question was not answered properly. So In this post I am going to show how to get the browser URL and extract the parameter from it.

 

Use below three lines of code in client script and get the required parameter value

 

 

 var url = top.location.href;
 var urlParms = new URLSearchParams(url);
 var groupName= urlParms.get('sysparm_group'); // you can put the parameter for which you need value

 

 

 For example,  browser URL is "https://{instanceName}.service-now.com/esc?id=sc_cat_item&sys_id=04b7e94b4f7b4200086eeed18110c7fd&sy...

 

In Above URL, two parameters "sys_id" & "sysparm_group" are  present. To get their value you can simply write code as below

 

 

 

 var url = top.location.href;
 var urlParms = new URLSearchParams(url);
 var groupName= urlParms.get('sysparm_group'); // you can put the parameter for which you need value
 var recordId= urlParms.get('sys_id'); 

 

 

SANDEEP28_1-1729093081802.png

 

See the Info message displaying group name and sys id in below screenshot .

 

SANDEEP28_2-1729093113433.png

 

If you find this post helpful, please hit the Thumb Icon.

 

 

 

0 REPLIES 0