- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2020 10:35 AM
I have a variable on a catalog item, 'location_name_ref', that is a reference to the cmn_location table. I have a single line text variable, 'site_address'. I believe an onChange script is needed to pull the 'street', 'city', 'state', 'zip' label display values from the 'location_name_ref' selection to the 'site_address' variable, but I'm not sure what that code looks like. We have something similar from a previous employee that pulls a user's email from a different reference variable to a single line text variable:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if(!isLoading && oldValue != newValue){
g_form.getReference('tech_contact_ref', getUserInfo);
}
}
function getUserInfo(userInfo){
g_form.setValue('technical_contact_email',userInfo.email);
}
For clarity, I would like to select ABC as the referenced location and have it auto populate the street, city, state, and zip from that location in another variable.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2020 11:24 AM
Hi Scott,
Try the below onChange client script on 'location_name_ref' variable.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
//Type appropriate comment here, and begin script below
if(newValue == ''){
g_form.clearValue('site_address');
}else{
var location = g_form.getReference('location_name_ref', callBack);
}
}
function callBack(location){
var site = location.street;
var city = location.city;
var state = location.state;
var zip = location.zip;
var address = site+"\n"+city+"\n"+state+"\n"+zip;
g_form.setValue('site_address', address);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2020 10:42 AM
you have to create Client Script and Script Includes like I mentioned here

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2020 11:24 AM
Hi Scott,
Try the below onChange client script on 'location_name_ref' variable.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
//Type appropriate comment here, and begin script below
if(newValue == ''){
g_form.clearValue('site_address');
}else{
var location = g_form.getReference('location_name_ref', callBack);
}
}
function callBack(location){
var site = location.street;
var city = location.city;
var state = location.state;
var zip = location.zip;
var address = site+"\n"+city+"\n"+state+"\n"+zip;
g_form.setValue('site_address', address);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2020 06:10 AM
This worked perfectly, thank you so much.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2020 06:18 AM
Best practice is to use to GlideAJAX instead of getReference. getReference gets all the fields from the table which takes lot longer then GlideAJAX which gets only specific fields which is much faster.