Catalog Client Script not setting the reference variable using URL parameter (value keeps reverting)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi team,
I’m working on a Catalog Client Script (onLoad) where I need to populate a reference variable (configuration_item) based on a URL parameter ci=1.
clearValue().- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
hey @SwethanaB
In Service Catalog, g_form.getParameter() does not reliably work for URL parameters. Also, reference variables may retain the last selected value due to cart/session caching, which is why clearValue() alone does not resolve the issue.
Instead, use g_request.getParameter() and pass a separate parameter for the CI sys_id (do not reuse sys_id, as that belongs to the catalog item).
URL format:
https://<instance>.service-now.com/<catalog_page>?id=sc_cat_item&sys_id=<catalog_item_sys_id>&ci=1&ci_sys_id=<ci_sys_id>
Catalog Client Script (onLoad):
function onLoad() {
// Always clear first to avoid cached value
g_form.setValue('configuration_item', '');
var ciFlag = g_request.getParameter('ci');
var ciSysId = g_request.getParameter('ci_sys_id');
if (ciFlag == '1' && ciSysId) {
// Small delay ensures it runs after form rendering
setTimeout(function() {
g_form.setValue('configuration_item', ciSysId);
}, 100);
}
}
*********************************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello Vaishali,
Thanks for the response!
I have tried the solution you provided but still I am getting the below error and it is taking the previously used data.
There is a JavaScript error in your browser console
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
that's not going to work
This will work in portal
function onLoad() {
var url = top.location.href;
var sysId = new URLSearchParams(url).get("sys_id");
alert(sysId);
g_form.setValue('configuration_item', sysId); // check variable name is correct
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
