not able to set the URL value in catalog item due to '&' as it is considering it as seperator

sachins1
Tera Contributor

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

Ankur Bawiskar
Tera Patron
Tera Patron

@sachins1 

try this

function onLoad() {
    var url = top.location.href;
    var params = new URLSearchParams(url.split('?')[1]);

    var name = decodeURIComponent(params.get("sysparm_employeename"));
    var manager = decodeURIComponent(params.get("sysparm_manager"));
    var department = decodeURIComponent(params.get("sysparm_department"));
    var title = decodeURIComponent(params.get("sysparm_title"));
    var startdate = decodeURIComponent(params.get("sysparm_startdate"));
    var reqID = decodeURIComponent(params.get('sysparm_sys_id'));
    var worklocation = decodeURIComponent(params.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);
}

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

sachins1
Tera Contributor

Hi Ankur,

Appreciate your quick response, i have checked it but it's giving 'null'.

sachins1_0-1740575473962.png

 

@sachins1 

what came in alert for those individual values? none of the values came?

Did you see that?

where are you testing this? portal or native?

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

sachins1
Tera Contributor

Yes, i checked alert as well and it came as blank. None of the values came. And it's native.