Need to populate field with the value coming from URL Parameters onload
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 06:42 AM
Hello
I have a requirement where i need to click on content item which will redirect to the record producer and onload of record producer i need to populate category field. i am sending category as url parameter from content item. i am sending as below in content item
/xyz?id=sc_cat_item&sys_id=34b896be1b6320104c6a54ea234bcbe2&sysparm_category=Colleague Data Changes
On load i am getting as below
/xyz?id=sc_cat_item&sys_id=34b896be1b6320104c6a54ea234bcbe2&sysparm_category=Colleague%20Data%20Changes
onload i can see category name is different, is there anyway i can get that category name exactly how i am sending from content item. because of this i am not able to set the value.
Thanks
Akash
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 07:01 AM
Hello,
Spaces are unsafe and need to be encoded, hence they're changed to %20, instead.
You aren't providing any information as far as what you're seeing the in the field itself, please give more information and this is somewhat inline with a question you've asked and had answered already: https://community.servicenow.com/community?id=community_question&sys_id=70c67580db03c5100d48db85ca96...
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 11:40 AM
I was able to find this at one point on a forum but I can't recall where. This is what we use on a catalog client script to auto fill an originating RITM number when a user clicks on a URL from an email that is generated in SN.
function onLoad() {
//Populate the variables with the parameters passed in the URL
//Use the 'getParmVal' function below to get the parameter values from the URL
var ticket = getParmVal('sysparm_ritm');
if(ticket){
g_form.setValue('og_ritm', ticket);
}
}
function getParmVal(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]);
}
}