Auto-populate user id in catalog item variable

Akshay Pundeer
Tera Contributor

I have created three variables On catalog item. employee _name. employee _id. employee _email.

Employee _name is a reference field with sys _user table.

I want to auto-populate user_id in employee _id and email in employee _email when a user is selected in the employee_name variable.

 

 

3 REPLIES 3

Utpal Dutta
Tera Guru

Hi Akshay,

Because user data is stored in Server you need to either write a script include or you need to get reference of employee name variable.

 

You may write below script in an onChange client script that will run on change of Employee Name variable.

 

var employee = g_form.getReference('employee_name', getEmployeeData); // getEmployeeData is our callback function
function getEmployeeData(employee ) { //reference is passed into callback as first arguments
g_form.setValue('employee_id',employee.username); //setValues of the fields that you want
 g_form.setValue('employee_email',employee.email); //setValues of the fields that you want
}

 

Please let me know if this approach doesn't work. We will try script include way of doing it. If it works then please mark my answer Correct.

 

Thanks,

Utpal

 

No It's not working

Omkar Mone
Mega Sage

Hello Akshay,

 

If your current version is UTAH, there is an OOB way to do this - https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-referenc...

 

IF not, you will have to write an onChange client script and call script include to get you the values. The above link should answer your question.

 

Regards,

Omkar