Not able retrieve URL Parameters through onload client script IN Portal

R Akash
Kilo Expert

Hello,

I have a requirement where i need to populate category for one of the catalog item on load where values are coming as URL Parameters.

I have written onLoad client script to get URL Parameters, but its not working in portal.

Onload URL: 

/fuse?id=sc_cat_item&sys_id=34b896be1b6320104c6a54ea234bcbe2&sysparm_category=Benifits

client script:

function onLoad() {
//Type appropriate comment here, and begin script below
var category=getParmVal("sysparm_category");
alert(category);
}

Do "getParmVal" will work in portal, if not is there any way to access these parameters onload of catalog item in portal?

 

 

Thanks

Akash

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage

Hi Akash,

I've used the following script. In the script, I'm setting the value to field named "field1" on the form.

function onLoad() {
    alert("hi");
    g_form.setValue('field1', getParameterValue('sysparm_category'));


    function getParameterValue(name) {
        var url = top.location.href;
        var value = new URLSearchParams(url).get(name);
        if (value) {
            return value;
        }
        if (!value) {
            try {
                var gUrl = new GlideURL();
                gUrl.setFromCurrent();
                value = gUrl.getParam(name);
                if (typeof value == 'undefined') {
                    return '';
                } else {
                    return value;
                }
            } catch (e) {}
        }
    }
}

Execution:

sp?id=sc_cat_item&sys_id=<sys_id of form>&sysparm_category=Benifits

find_real_file.png

View solution in original post

5 REPLIES 5

Thanks for your help, Its working now.