URLSearchParams and Description field containing URLs

Luiz Lucena
Mega Sage

Hello Community, 

I'm facing a challenge here; we have a custom form called Generic Request and we started using Universal Request in an attempt to stop using Generic Requests. However, our outsourced Service Desk requested to be able to transfer some of those Universal Requests to Generic. So far so good, we did that for them and here is the script that is doing. 

 

function onLoad() {

    var url = top.location.href;
    var ur_id = new URLSearchParams(url).get("universal_request_sys_id");
    var ur_openedFor = new URLSearchParams(url).get("ur_openedFor");
    try {
        var ur_sd = new URLSearchParams(url).get("ur_sd");
        var ur_desk = new URLSearchParams(url).get("ur_desc");
    } catch (err) {
        console.log("ur_sd and ur_desk doesn't exist");
    }

    //make sure the reload of the already submitted page doesn't populate the UR variable
    var apps = new GlideAjax('UniversalRequest_Utils_BP');
    apps.addParam('sysparm_name', 'checkExistingUR');
    apps.addParam('sysparm_urid', ur_id);
	apps.getXML(checkUR);

    function checkUR(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');

        if (answer == "true") {
            g_form.clearValue('universal_request_id');
        } else {

            g_form.setValue('universal_request_id', ur_id);

            if (g_form.getUniqueValue() == "ddf753e2db9d47c0ad59d7795e96197f") { //Generic Request

                if (ur_sd != undefined && ur_sd != "") {
                    g_form.setValue('short_description', ur_sd);

                }
                if (ur_desk != undefined && ur_desk != "") {

                    var parseDesc = ur_desk.replace(/newLine/g, '\n');
                    g_form.setValue('description', parseDesc);

                }

            }

            if (ur_openedFor != undefined && ur_openedFor != "") {

                if (g_form.getValue("u_requested_by") != "" && g_form.getValue("u_requested_by") != undefined) {
					
                    g_form.setValue('u_requested_by', ur_openedFor);
                }

            }
        }

    }

}

 

 

It works well if the Description field contains regular text. 
But if it contains any URL or anything like &id=, the custom UI action to Create Request won't work. 

Here is an example, the text below is from Universal Request description field.

"Can we please open up read access to the above Sales Toolkit page for all of UST?

https://[website_goes_here]/Forms/AllItems.aspx?FolderCTID=0x01200094474C796B23974FA55619F23C94DDEC&id=%2Fsites%2FUST%2Fsalestoolkit%2FProcess%20and%20Tools%2FTerritory%20Maps%20and%20Contact%20Sheets%2FSales&viewid/=98eafa0a%2D03ec%2D4aca%2Da5bb%2D3dcf20360293"

 

The red piece above is the part causing issues, the portal would load like this in the address bar:
https://{instance_name].service-now.com/sp?id=sc_cat_item&id=%2Fsites%2FUST%2Fsalestoolkit%2FProcess%20and%20Tools%2FTerritory%20Maps%20and%20Contact%20Sheets%2FSales&sys_id=ddf753e2db9d47c0ad59d7795e96197f&sysparm_category=d258b953c611227a0146101fb1be7c31&universal_request_sys_id=912159571b24b194a0760ed7cc4bcb5f&ur_sd=Sales%20Toolkit%20Access%20to%20UST&ur_desc=Can%20we%20please%20open%20up%20read%20access%20to%20the%20above%20Sales%20Toolkit%20page%20for%20all%20of%20UST%3FnewLinenewLinehttps:%2F%2Fatconline.sharepoint.com%2Fsites%2FUST%2Fsalestoolkit%2FProcess%20and%20Tools%2FForms%2FAllItems.aspx%3FFolderCTID%3D0x01200094474C796B23974FA55619F23C94DDEC&viewid%2F=98eafa0a-03ec-4aca-a5bb-3dcf20360293&ur_openedFor=f1a9c0a9dbb8c300e7ea534e5e96190e

Even though the description field is the one in bold above, part of it is causing the issue (in red). I've added a slash between the & and the id=, the description was passed to the form, but not entirely, the URL in the description field was broken, stopping at the letters DDEC.

How should we improve that script in order to pass URLs correctly as a text?

As workaround, I suggested Service Desk to remove URLs from Description field and add a notepad or word doc with it.

 

Thanks in advance,

 

EDIT:
The ampersand is the culprit! 

0 REPLIES 0