- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 05:18 AM
I would like to auto-populate a 'Location' field based on the person selected in the 'New Hire' field. Trying to do this using Default Value, but not working:
javascript:gs.getUser(current.variables.new_hire_name).getRecord().getValue('u_location');
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2018 04:59 AM
I was able to get this working by changing the variable type to 'reference', and using the following code:
function onChange(control, oldValue, newValue, isLoading) {
//Type appropriate comment here, and begin script below
var newHire = g_form.getValue('new_hire_name');
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', newHire);
user.query(setLocation);
function setLocation (user){
if ( user.next() ){
g_form.setValue('location_1', user.location);
g_form.setValue('location_2', user.location);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 06:07 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 06:11 AM
Hi
so gs.getUser() gets the current logged in user. In this case you will have if you try impersonating you will see the difference.
I recommend you to write a script include and Client script to get the current location of the user on the new_hire_name feild.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 06:22 AM
you can write a script include for this and return the value, If you want I can help you with writing one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 06:13 AM
Hi Nicole,
You are getting your location is because gs.getUser() does not consider any parameters. It will take the current logged in user as its glidereocrd object. To achieve your requirement, I would suggest you to write a script include and pass the new_hire_name to the script include method and get the location of the user and return it.
Regards,
Manan Raval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 06:57 AM
I was able to get this working with a client script, however, it is displaying as a sys_id. How can I get the actual location to display?:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var newHire = g_form.getValue('new_hire_name');
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',newHire);
user.query();
if ( user.next() )
{
g_form.setValue('location_1', user.location);
}