How to dynamically populate field based on another field

Martin133s
Tera Contributor

Hi, I would like to automatically populate value to field when another field value is selected. I added a new field on a incident table called " u_ci_class" and this field is reference field from table 'Configuration Item (cmdb_ci). I want to fill this value when related value 'Configuration item' from the incident table is selected. These values are related to each other in a Configuration Item (cmdb_ci) table. In default, each Configuration Item has own class which I want get. So, what is the best way to make it wokrs? Thank you for your suggestions. Check the attachment for better understanding of my goal.

2 REPLIES 2

Sarika S Nair1
Kilo Sage

Hi @Martin133s , 

If both fields are reference type then the display value will be same.. I mean in 'u_ci_class' it will be showing the configuration item name instead of class since configuration item name field has display value true in cmdb table..

 

Better create a choice field or string field for u_ci_class field 

 

and in order to populate the u_ci_class you can use onchange client script with below code. 

if(newValue!=oldValue){

var cmdbclass = g_form,getReference('<cmdbfieldname>',getCMDBClass);

function getCMDBClass(cmdbclass){

g_form.setValue('u_ci_class',cmdbclass.class);

}

}

 

Hi @Sarika S Nair1, thank you. Your proposed solution is almost working correctly, but there is still one issue. The value returned from the on change script is "system value" instead of "display value", so it means that I will get value "cmdb_ci_computer" instead of "Computer".