How to Read URL Parameters in ServiceNow Client Scripts
- kelly.ryu
- Mar 18
- 2 min read
Updated: Apr 1

Reading URL parameters in ServiceNow Client Scripts allows for dynamic form interactions and enhanced user experiences. URL parameters, typically structured as query strings (e.g., ?param1=value1¶m2=value2), can pre-populate form fields, customize record producer behavior, or transfer data between forms. This guide provides practical methods and best practices for retrieving URL parameters using standard Client Scripts in ServiceNow.
Understanding URL Parameters
URL parameters are appended to URLs in key-value pairs, facilitating the passing of data to forms or scripts. For example:
https://instance.service-now.com/sc_catitem.do?sysparm_id=12345&sysparm_full_name=John%20Doe
Here, sysparm_id=12345 and sysparm_full_name=John%20Doe represent parameters that automatically populate form fields.
Recommended Method: Using JavaScript's window.location
Since GlideURL is unavailable in some contexts such as Catalog Client Scripts, the most reliable alternative method involves using JavaScript's built-in window.location object combined with the URLSearchParams API:
function getParamValue(paramName) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(paramName);
}
function onLoad() {
const comments = getParamValue('sysparm_comments');
if (comments) {
g_form.setValue('description', decodeURIComponent(comments));
}
}
In this example:
window.location.search retrieves the query string from the URL.
URLSearchParams parses the query string, making it easy to access parameter values.
decodeURIComponent() ensures readable parameter values by decoding any URL-encoded characters.
g_form.setValue() populates the form field.
Common Issues and Solutions
GlideURL Not Available: GlideURL isn't supported in certain contexts such as Service Portal or mobile views. In these cases, JavaScript's window.location is recommended.
Decoding URL Parameter Values: Always decode URL parameters to handle encoded characters properly.
Check for Parameter Presence: Implement conditional checks to gracefully handle missing parameters and prevent script errors.
Best Practices
Avoid using legacy DOM manipulation methods (document.URL.parseQuery()) due to potential compatibility and security issues.
Validate and sanitize URL parameter values before use to ensure data integrity and security.
Properly handling URL parameters in ServiceNow Client Scripts significantly improves form usability and user interactions. When GlideURL is unavailable, using JavaScript's native window.location and URLSearchParams is a robust alternative. Adhering to best practices ensures reliable, secure, and user-friendly implementations in ServiceNow.