The CreatorCon Call for Content is officially open! Get started here.

onChange client script returning 'undefined'

lando321
Tera Contributor

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);
	}  
}

 

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

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.

 

View solution in original post

10 REPLIES 10

Yeah the field name can you mark my answer as correct.

 

Thanks.