Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Populate user location using default value

nicolemccray
Tera Expert

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');

 

1 ACCEPTED SOLUTION

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);
        }
    }
}

View solution in original post

15 REPLIES 15

Omkar Mone
Mega Sage

Hi 

Try this :- gs.getUser(current.variables.new_hire_name).getDisplayValue("location").

 

Mark correct if it helps.

 

Regards,

Omkar Mone

www.dxsherpa.com

 

Shashi Bhushan
Kilo Guru

javascript:gs.getUser(current.variables.new_hire_name).getRecord().getDisplayValue("u_location"); Please mark answer as correct or helpful. Thanks

nicolemccray
Tera Expert

I was able to get a location to populate using this:

javascript:gs.getUser(current.variables.new_hire_name).getRecord().getDisplayValue('location');

 

But it is populating MY location, and not the location of the person in the 'new_hire_name' field.

hi 

So please tell me where are you doing this ?