Populate reference field (sys_user) with user name based on choice from select box field

m_larson
Tera Contributor

Hi,

I have 2 fields on my catalog item form : departments(select box) and manager(reference).

If I choose for example in departments "choice_1" I want to display in manager field specified user name ex. John Deer from sys_user table. I tried to copy sys_id of this person and create client script onChange like : 

var department = g_form.getValue('departments');

if(department == 'Finance'){

g_form.setValue('manager', 'sys_id_of_user')

}

 

I will appreciate any help 

3 REPLIES 3

Community Alums
Not applicable

Hi @m_larson ,

 

I assume you are refering Catalog Variables and writing onChange Catalog client script. 

 

If this is the case, then the code should. Are you facing any issue?

 

Regards,

Gagan k

 Eg - 

Yeah thats right the reference field is still empty after change departament on the form

Community Alums
Not applicable

Its not a great idea to hard-code sys_ids within client scripts. Instead, try to use a GlideAjax call from your client script to retrieve the manager of the group (sys_user_group) or some such logic so that when the person changes, your code still works.

 

ArunChaturved1_0-1684278412631.png