How to Retrieve URL Parameters in Catalog Client Script (Challenge ID Example)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2025 11:42 PM
Title: How to Retrieve URL Parameters in Catalog Client Script (Challenge ID Example)
Hi everyone,
Today I’d like to share a solution to a common issue that many developers might encounter while working with ServiceNow catalog client scripts.
🧩 Problem Statement:
I needed to extract a specific parameter (challenge) from a URL and use it within a catalog client script. The URL looked like this:
https://devsc3847.service-now.com/ignite?id=labs_sc_cat_item&sys_id=f58a1bb45a69cebb3535&challenge=5598819387872e103c49ca69cebb35c1
My goal was to retrieve the value of the challenge parameter (5598819387872e103c49ca69cebb35c1) and use it in the script. I tried several methods like getParameter and other built-in approaches, but none worked as expected.
✅ Solution:
After some trial and error, I found a reliable way to extract the parameter using a custom JavaScript function. Here's the code snippet:
function getParameterValue(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(top.location); if (results == null) { return ""; } else { return unescape(results[1]); } } var challengeId = getParameterValue('challenge');
alert(challengeId); alert specified parameter. In this case, it successfully retrieves the `challenge` ID. 🙌 Conclusion: If you're facing a similar issue, feel free to try this approach. It’s simple, effective, and works well in catalog client scripts. Let me know your thoughts or if you have alternative methods—I'd love to hear them! Thanks & Regards,
Sahil Negi ServiceNow Developer