Catalog Script: To concatenate shipping address from location on change

Scott29
Kilo Sage

I have a catalog item:

Scott29_0-1748553490117.png

 

The location field comes from "cmn_location".

 

 

What would the on modify client script look like to populate the shipping address field by concatenating the street, city, state, and zip / postal code from the associated location table reference?

 

1 ACCEPTED SOLUTION

Juhi Poddar
Kilo Patron

Hello @Scott29 

To achieve this, create an onChange client script on the Location field.

Configuration setup:

JuhiPoddar_0-1748570913979.png

Script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
// Fetch the selected location record and populate address
    //g_form.addInfoMessage("Inside client script");
    var locationGr = g_form.getReference("location", populateAddress);

    function populateAddress(locationGr) {
        var street = locationGr.street;
        var city = locationGr.city;
        var state = locationGr.state;
        var zip = locationGr.zip;
        var address = street + "\n" + city + "\n" + state + "\n" + zip;
		//g_form.addInfoMessage("Address: "+ address);
        g_form.setValue("address", address);
    }
}

Result:

When a user selects a Location, the corresponding Address field is automatically populated with the street, city, state, and zip code from the selected location record.

JuhiPoddar_1-1748570968122.png

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

View solution in original post

1 REPLY 1

Juhi Poddar
Kilo Patron

Hello @Scott29 

To achieve this, create an onChange client script on the Location field.

Configuration setup:

JuhiPoddar_0-1748570913979.png

Script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
// Fetch the selected location record and populate address
    //g_form.addInfoMessage("Inside client script");
    var locationGr = g_form.getReference("location", populateAddress);

    function populateAddress(locationGr) {
        var street = locationGr.street;
        var city = locationGr.city;
        var state = locationGr.state;
        var zip = locationGr.zip;
        var address = street + "\n" + city + "\n" + state + "\n" + zip;
		//g_form.addInfoMessage("Address: "+ address);
        g_form.setValue("address", address);
    }
}

Result:

When a user selects a Location, the corresponding Address field is automatically populated with the street, city, state, and zip code from the selected location record.

JuhiPoddar_1-1748570968122.png

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar