- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 08:29 AM
Hello all,
I am trying to populate the dept code with an onChange client script, but it keeps returning 'undefined' when i attempt to dot walk to the id field on the department table. When i use getDisplayValue() the field does not return anything at all. Would greatly appreciate any help.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue){
var caller = g_form.getReference('name', popDept);
}
function popDept(caller){
g_form.setValue('department_code', caller.department_id);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 10:02 AM - edited 10-13-2022 10:04 AM
Hello,
So it is basically you have to dot walk two times, please use the below code:-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var caller = g_form.getReference('name');
var dept = caller.department;
if (dept) {
var grDept = new GlideRecord('cmn_department');
if (grDept.get(dept)) {
g_form.setValue('department_code', grDept.department_id);
}
}
}
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 10:17 AM
Yeah the field name can you mark my answer as correct.
Thanks.