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

onChange Client Script - Incident Form

Eric S1
Tera Contributor

I am trying to fill a field on incident form based on change on configuration item using the code below.  It is not working. Also when I checked, the data is from this table cmdb_ci_business_app since the category selected for the incident is business apps.  Please help.  

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    
    if(g_form.getValue('cmdb_ci')!=''){
        var citem = g_form.getReference('cmdb_ci');
        g_form.setValue('u_ado_project',citem.x_adbad_app_cr_ado_project);
    }
    
}
6 REPLIES 6

pablo_itguy_pl
Mega Guru

Try using callback function:

if (g_form.getValue('cmdb_ci') != '') {
    var citem = g_form.getReference('cmdb_ci', setNewValue);

    function setNewValue(citem) {
        g_form.setValue('u_ado_project', citem.x_adbad_app_cr_ado_project);
    }
}

 

Hi,

 

I tried callback but it is still not working.  Here is my revised code:

 

   var ci = g_form.getReference('cmdb_ci',callback);
 
function callback (ci) {
g_form.setValue('u_ado_project',cmdb_ci.x_adbad_app_cr_ado_project);
  alert('CI status is TEST2');
}
}

Eric S1
Tera Contributor

I further modified the setValue part.  See below.  The target field was set to "undefined".  

 

g_form.setValue('u_ado_project',ci.x_adbad_app_cr_ado_project);

That's what you'll get when the field name that you supply doesn't exist on the referenced table, cmdb_ci in this case.