- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 12:30 AM
Hello,
I have a requirement where i need to populate category for one of the catalog item on load where values are coming as URL Parameters.
I have written onLoad client script to get URL Parameters, but its not working in portal.
Onload URL:
/fuse?id=sc_cat_item&sys_id=34b896be1b6320104c6a54ea234bcbe2&sysparm_category=Benifits
client script:
function onLoad() {
//Type appropriate comment here, and begin script below
var category=getParmVal("sysparm_category");
alert(category);
}
Do "getParmVal" will work in portal, if not is there any way to access these parameters onload of catalog item in portal?
Thanks
Akash
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 01:46 AM
Hi Akash,
I've used the following script. In the script, I'm setting the value to field named "field1" on the form.
function onLoad() {
alert("hi");
g_form.setValue('field1', getParameterValue('sysparm_category'));
function getParameterValue(name) {
var url = top.location.href;
var value = new URLSearchParams(url).get(name);
if (value) {
return value;
}
if (!value) {
try {
var gUrl = new GlideURL();
gUrl.setFromCurrent();
value = gUrl.getParam(name);
if (typeof value == 'undefined') {
return '';
} else {
return value;
}
} catch (e) {}
}
}
}
Execution:
sp?id=sc_cat_item&sys_id=<sys_id of form>&sysparm_category=Benifits

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 12:35 AM
Hi,
Please go through below mail thread, it may help you.
https://community.servicenow.com/community?id=community_question&sys_id=dab68b65db1cdbc01dcaf3231f9619cf
https://servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script/
Kindly mark correct/helpful, if its helpful

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 12:38 AM
Hello R Akash,
You need to declare the function getParmVal:
var myparm = getParmVal('sys_myparm');
function getParmVal(name) {
var url = document.URL.parseQuery();
if (url[name]) {
return decodeURI(url[name]);
} else {
return;
}
}
So your client script should look like:
function onLoad() {
//Type appropriate comment here, and begin script below
var category=getParmVal("sysparm_category");
alert(category);
function getParmVal(name) {
var url = document.URL.parseQuery();
if (url[name]) {
return decodeURI(url[name]);
} else {
return;
}
}
}
Hope this helps!
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Filipe Cruz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 12:58 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 01:46 AM
Hi Akash,
I've used the following script. In the script, I'm setting the value to field named "field1" on the form.
function onLoad() {
alert("hi");
g_form.setValue('field1', getParameterValue('sysparm_category'));
function getParameterValue(name) {
var url = top.location.href;
var value = new URLSearchParams(url).get(name);
if (value) {
return value;
}
if (!value) {
try {
var gUrl = new GlideURL();
gUrl.setFromCurrent();
value = gUrl.getParam(name);
if (typeof value == 'undefined') {
return '';
} else {
return value;
}
} catch (e) {}
}
}
}
Execution:
sp?id=sc_cat_item&sys_id=<sys_id of form>&sysparm_category=Benifits