- 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
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 12:09 PM
Thanks for the advice Sanjiv! I got the address field to load using the script include you recommended, this was the code i used:
function getUserAddress()
{
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
return user.getDisplayValue('location.street')+', '+user.getDisplayValue('location.city')+', '+user.getDisplayValue('location.state')+', '+user.getDisplayValue('location.zip')+', '+user.getDisplayValue('location.country') ;
}
My only question is now how do I call this function in an onChange catalog client script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2018 12:18 PM
In the onchange, try with belo script
var user = new GlideRecord('sys_user');
user.get(g_user.UserID);
var loc = new GlideRecord('cmn_location');
loc.get(user.location);
var loc = loc.street+', '+loc.city+', '+loc.state+', '+loc.zip+', '+loc.country;
g_form.setValue('your location field',loc);
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 12:59 PM
The correct location field is changing however all the values are coming back undefined. This was the code I used:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user = new GlideRecord('sys_user');
user.get(g_user.UserID);
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);
}