Populate reference field (sys_user) with user name based on choice from select box field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2023 03:53 PM - edited ‎05-16-2023 03:53 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2023 04:03 PM
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 -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2023 04:07 PM
Yeah thats right the reference field is still empty after change departament on the form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2023 04:07 PM
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.