not able to set the URL value in catalog item due to '&' as it is considering it as seperator
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2025 04:50 AM
Hi All,
I am trying to get the values through an URL and put them on different fields in a catalog item. In the same process a field where value/Text should be set as 'Marketing & specialist' . I am only getting 'Marketting' and rest is missing as i believe it is considering '&' as seperator. So in URL instead of '&' it's showing '%26'.
Here is my script:
function onLoad() {
var url = top.location.href;
var name = new URLSearchParams(url).get("sysparm_employeename");
alert(name);
var manager = new URLSearchParams(url).get("sysparm_manager");
var department = new URLSearchParams(url).get("sysparm_department");
var title = getDecodedParam("sysparm_title");
var startdate = new URLSearchParams(url).get("sysparm_startdate");
var reqID = new URLSearchParams(url).get('sysparm_sys_id');
var worklocation = new URLSearchParams(url).get("sysparm_location");
var dt = startdate.split(' ')[0];
g_form.setValue('employeename', name);
g_form.setValue('manager', manager);
g_form.setValue('department', department);
g_form.setValue('job_title', title);
g_form.setValue('start_date', dt);
g_form.setValue('work_location', worklocation);
g_form.setValue('reqnumber', reqID);
}
I have tried using decodeURIComponent as well as EncodeURIComponent but nothing worked.
Any help would be appreciated.
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2025 05:38 AM
in native that won't work
try this
function onLoad() {
var gUrl = new GlideURL();
gUrl.setFromCurrent();
var name = decodeURIComponent(gUrl.getParam("sysparm_employeename"));
var manager = decodeURIComponent(gUrl.getParam("sysparm_manager"));
var department = decodeURIComponent(gUrl.getParam("sysparm_department"));
var title = decodeURIComponent(gUrl.getParam("sysparm_title"));
var startdate = decodeURIComponent(gUrl.getParam("sysparm_startdate"));
var reqID = decodeURIComponent(gUrl.getParam('sysparm_sys_id'));
var worklocation = decodeURIComponent(gUrl.getParam("sysparm_location"));
var dt = startdate.split(' ')[0];
g_form.setValue('employeename', name);
g_form.setValue('manager', manager);
g_form.setValue('department', department);
g_form.setValue('job_title', title);
g_form.setValue('start_date', dt);
g_form.setValue('work_location', worklocation);
g_form.setValue('reqnumber', reqID);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader