Add URL parameters using catalog client script without reloading the form

Ashwin perumal
Tera Contributor

Hi All,
I am trying to append a value of a URL using on load catalog client for a order guide. My requirement is I need to have a parent catalog variable value appended in URL when user clicks on next button in order guide. I wrote an on load client script on the child catalog item level as when user clicks on next it will display that catalog item. The script is appending the parameter in URL, but the form is reloaded and moved back to order guide initial form itself.

I tried many options like history.pushState(), history.replaceState()  and  other methods mentioned in community and other sources. But nothing worked out to me and everytime value added in URL it starts reloading and move backs to parent catalog item (i.e.) the order guide form itself.

The script which I am trying:

 

function onLoad() {

    var model = g_form.getValue('model');
    var currentUrl = new URL(self.location.href);
    if (currentUrl);
    var params = new URLSearchParams();
    params.append('sys_value', model);

    var newUrl = 'instancename/esc?id=sc_cat_item_guide&sys_id=dc8ded43c30176109092bd73e4013139' + '&' + params;
    history.pushState(nullnull, newUrl);

}
 
This script appends the correct value in URL but gets reloaded and go to initial form itself. Can anyone pls help me how to achieve this in client  script.

Thanks in advance.
1 REPLY 1

JenniferRah
Mega Sage
Mega Sage

I'm confused as to what value you're trying to achieve. Could you not just do an Item Variable Assignment and assign the value you're trying to pass directly into a variable on the form you're submitting?