Client Script help, how to check CI for if value is empty

Jay Jay
Giga Expert

I have this script that sets values on INC/CHG/PROB forms if field is empty. By customer requirement I wish to change it so that it allways overwrite values in form, but only if field is not empty in the CI it gets value from.

 

To sum it up. CI gets selected on incident form, it checks if CI has value in Ass group, category and subcategory and if it does overwrite values on Incident form. How should i alter below script ?

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
 if (isLoading || newValue === '') {
 return;
 }
 var ci = g_form.getReference('cmdb_ci', getci);
 //Type appropriate comment here, and begin script below
 
}

 

function getci(ci){
if (g_form.getValue('category')== '' && ci.category !='')
 {
 
 g_form.setValue('category', ci.category);
 }
 if (g_form.getValue('subcategory')== '' && ci.subcategory !='')
 {
 
 g_form.setValue('subcategory', ci.subcategory);
 }
 
 
 
 
 if (g_form.getValue('assignment_group')== '' && ci.assignment_group !='')
 {
 
 g_form.setValue('assignment_group', ci.assignment_group);
 }
 
 
 
 
}
 
1 ACCEPTED SOLUTION

You need to have if conditions to check whether category on ci is empty or not

Try the below script

 


function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var ci = g_form.getReference('cmdb_ci', getci);
    //Type appropriate comment here, and begin script below
}


function getci(ci){
    if (ci.category !='')
        {
        g_form.setValue('category', ci.category);
    }
    
    
    if (ci.subcategory !='')
        {
        g_form.setValue('subcategory', ci.subcategory);
    }
    
    
    if (ci.assignment_group !='')
        g_form.setValue('assignment_group', ci.assignment_group); {
        
    }
    
}

View solution in original post

6 REPLIES 6

You need to have if conditions to check whether category on ci is empty or not

Try the below script

 


function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var ci = g_form.getReference('cmdb_ci', getci);
    //Type appropriate comment here, and begin script below
}


function getci(ci){
    if (ci.category !='')
        {
        g_form.setValue('category', ci.category);
    }
    
    
    if (ci.subcategory !='')
        {
        g_form.setValue('subcategory', ci.subcategory);
    }
    
    
    if (ci.assignment_group !='')
        g_form.setValue('assignment_group', ci.assignment_group); {
        
    }
    
}

Solved it. Thank you 🙂