How to get value/string from URL after & symbol .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 12:43 AM
Hi All,
I have a requirement to populate the value from URL, actual value is(&sysparm_phase=6%20test%20&%20plan) '6 test & plan' i am able to get till '6 test' but '& paln ' is not populating it is trimming off, so what needs to changed in client scritpt to get full value.
Quick help is appreciated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 12:47 AM
Hello @Neelavathi M
Can you send current script you are using to get the value?
Thank you,
Ali
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 12:48 AM
you can refer below thread to get read URL parameters in client script:
https://www.servicenow.com/community/csm-forum/get-url-parameters-from-client-script/m-p/389334
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 01:04 AM
Hello @Neelavathi M
You can try this script:
function onLoad() {
//Type appropriate comment here, and begin script below
var url = top.location.href; // Current URL
var urlParams = new URLSearchParams(url.split('?')[1]); // Extract query string
// Decode the sysparm_phase parameter
var sysparmPhase = urlParams.get('sysparm_phase');
g_form.addInfoMessage('sysparmPhase' + sysparmPhase);
if (sysparmPhase) {
sysparmPhase = decodeURIComponent(sysparmPhase); // Decode special characters
alert("sysparm_phase value:", sysparmPhase);
// Populate the value into the desired field
//g_form.setValue('your_field_name', sysparmPhase);
}
}
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 01:15 AM - edited 01-03-2025 01:21 AM
Hello @Neelavathi M
In addition to my previous answer, I see that '6 test & plan' contains '&' which act as a delimiter.
When passing parameters via a URL in ServiceNow, special characters like & need to be encoded to avoid truncation or unexpected behavior. The & character is treated as a delimiter for query parameters in URLs. You need to ensure that the parameter value is properly URL-encoded and decoded to preserve its integrity.
Note: Update the url as (&sysparm_phase=6%20test%20%26%20plan). This will give the expected results as '6 test & plan'
Result:
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar