- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2018 05:19 PM
Does anyone know how to script this? Been at it for a while and can't figure it out.
Currently on the sys_user table there is a location reference field. This field has a 3 digit location ID. Upon clicking the info button next to this field, it redirects to the cmn_location table that has the address fields for that user that they require.
I created a record producer, and need to set the default value of a single line text field with the concatenated values of the current requested for user's address upon load. The fields I require from the cmn_location table are: street, city, state, zip and country.
After this loads successfully, whenever the requested for user is changed, I need to auto populate this same single line text field with the concatenated location values of whichever other user is selected. It needs to be a single line text field since the customer wants this address field to be editable.
I've tried making an onChange catalog script on the record producer but can't seem to make it work, nor can I figure out how to set the default value. I'm not that great with javascript, if anyone can lend a hand, I'd really appreciate it!
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2018 05:31 PM
On the text field, you can set the Default field in the variable dictionary and call a class less script.
In the default field write javascript: getUserAddress()
The script include name can be
getUserAddress
in script should be
function getUserAdderss()
{
var user = new GlideRecord('sys_user');
user.get(gs.getUserID())
return user.name+','+user.street+','+user.city+','+user.zip+','+user.zip;
}
Let me know, if this works, then we can work on the onChange script
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2018 01:20 PM
Added some alerts and Corrected one code line as well
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user = new GlideRecord('sys_user');
user.get(newValue);
alert('User location is '+user.location);
var loc = new GlideRecord('cmn_location');
loc.get(user.location);
var locfield = loc.street+', '+loc.city+', '+loc.state+', '+loc.zip+', '+loc.country;
g_form.setValue('lease_refresh_hardware_request_location_of_end_user_for_delivery',locfield);
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2018 03:01 PM
hey Sanjiv, results are still coming back undefined. Any other ideas?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2018 03:20 PM
Try this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',newValue);
user.query();
if (user.next())
{
alert('User location is '+user.location);
var loc = new GlideRecord('cmn_location');
loc.addQuery('sys_id',user.location);
loc.query()
if (loc.next())
var locfield = loc.street+', '+loc.city+', '+loc.state+', '+loc.zip+', '+loc.country;
g_form.setValue('lease_refresh_hardware_request_location_of_end_user_for_delivery',locfield);
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2018 05:54 PM
var getUserAddress = Class.create();
getUserAddress.prototype = {
initialize: function getUserAddress() {
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
return user.name+','+user.street+','+user.city+','+user.zip+','+user.country;
},
type: 'getUserAddress'
};
Not working Sanjiv. I tried your code, as well the code above. Additionally I tried referencing the cmn_location table instead of the sys_user table in the gliderecord call (since that's where the address fields are) but that didn't work either. Any other ideas?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2018 11:16 PM
Hi,
Add below code to attribute section of variable, and provide values as per need
here i have tried with user table to get multiple values like emp number,location etc.
ref_auto_completer=AJAXTableCompleter,ref_ac_columns=employee_number;location,ref_ac_columns_search=true
and write onChange client script to change value of location if user change.
Thanks.
Tripti S.