Solution - How to Get browser URL parameters in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 08:43 AM - edited 10-16-2024 09:00 AM
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');
See the Info message displaying group name and sys id in below screenshot .
If you find this post helpful, please hit the Thumb Icon.