Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

@sachins1 

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