- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 02:20 PM
I have a catalog item:
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 07:13 PM
Hello @Scott29
To achieve this, create an onChange client script on the Location field.
Configuration setup:
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 07:13 PM
Hello @Scott29
To achieve this, create an onChange client script on the Location field.
Configuration setup:
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.
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