auto populate current user and its location

sp_18
Giga Contributor

Hi,

i have this catalog item with variables-

find_real_file.png

I want auto populate the Applicant's Name field with logged in user and auto populate the location field of the current user with onload action.

 

what will be the onload client script?

Thank you.

 

1 ACCEPTED SOLUTION

sashichand
Mega Expert

 

Hi,

To auto populate the Applicant's Name field with logged in user - While defining the variable, set the default value as javascript:gs.getUserID(); ------- This will give you the current logged in user.

To auto populate the location field of the current user with onload action.

write an onLoad script:

var id = g_form.getValue('applicant_name'); //variable name
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',id);
user.query();
if ( user.next() ) {
g_form.setValue('location', user.location);

g_form.getValue('requestor_manager', user.manager);
g_form.setValue('phone', user.mobile_phone); //to set the phone number.
g_form.setValue('emp_number', user.employee_number); // to set the employee number.

}

 

Hope this will be helpful?

 

Thanks,

Shashikant

View solution in original post

10 REPLIES 10

johannesgrosbøll that worked for me and it's so much cleaner - thank you!

Hi Johan,

 

I tried to implement the same default value but not able to get the value auto populated. my reference table for location variable is "cmn_location" and i even tried with "sys_user" reference. Could you please suggest. Thank you!

Try JavaScript:gs.getLocation();

Hi ,

I have used the same code but am getting sys_id of the manager as shown below

find_real_file.png

please help me on this.

 

Thanks,

Jenny

 

Hi Jenny,

Is your "Line Manager Approval" field of the type String or Reference? It should be Reference, pointing to the cmn_location table.