Add option & remove option in Onchange client script

SNOW32
Giga Expert

Hi All,

I am trying addOption & removeOption for selection of resolution category if u_function field change. elseif option is not working, choices are incorrect

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var func = g_form.getValue('u_function');

if(func == 'cad'){

g_form.addOption('u_resolution_category','user_error');
g_form.addOption('u_resolution_category','other');

g_form.removeOption('u_resolution_category','issue');
g_form.removeOption('u_resolution_category','application-bug');

}

else if(func == 'it') { 
g_form.addOption('u_resolution_category','application-bug');
g_form.addOption('u_resolution_category','other');

g_form.removeOption('u_resolution_category','issue');
g_form.removeOption('u_resolution_category','user_error');

//Type appropriate comment here, and begin script below

}
else {
g_form.addOption('u_resolution_category','issue');
g_form.addOption('u_resolution_category','other');

g_form.removeOption('u_resolution_category','application-bug');
g_form.removeOption('u_resolution_category','user_error');
}
}

When I choose the "IT" option which matches the elseif condition,but the resolution category choices are removing all options.

Please help me where I am wrong

thanks,

Swetha

 

 

 

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Can you try replacing else-if with below.

else if(func == 'it') { alert('Inside else if');
g_form.addOption('u_resolution_category','application-bug');
g_form.addOption('u_resolution_category','other');

g_form.removeOption('u_resolution_category','issue','Issue'); //where Issue is choice label
g_form.removeOption('u_resolution_category','user_error','User Error'); //where User Error is choice label

//Type appropriate comment here, and begin script below

}

View solution in original post

7 REPLIES 7

Community Alums
Not applicable

this code seems to be not working for me :

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var loc = g_form.getValue('location');
    g_form.clearOptions('building');
    if (loc == 'C') {
        g_form.addOption('building''SC');
        g_form.addOption('building''DLF1');
        g_form.addOption('building''DLF2');
    } else if (loc == 'B') {
        g_form.addOption('building''WPB');
        g_form.addOption('building''ITOPS');
        g_form.addOption('building''WTC');
    } else {
        g_form.addOption('building''CKPA');
        g_form.addOption('building''CKPB');
    }
}

Community Alums
Not applicable

Now this code is working!!!

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var loc = g_form.getValue('location');
    if (loc == 'C') {
        g_form.removeOption('building''WPB');
        g_form.removeOption('building''ITOPS');
        g_form.removeOption('building''WTC');
        g_form.removeOption('building''CKPA');
        g_form.removeOption('building''CKPB');
        g_form.addOption('building''SC','SIPCOT');
        g_form.addOption('building''DLF1','DLF Phase I');
        g_form.addOption('building''DLF2','DLF Phase II');
    } else if (loc == 'B') {
        g_form.removeOption('building''SC');
        g_form.removeOption('building''DLF1');
        g_form.removeOption('building''DLF2');
        g_form.removeOption('building''CKPA');
        g_form.removeOption('building''CKPB');
        g_form.addOption('building''WPB','Whitefields-Process Block');
        g_form.addOption('building''ITOPS','Whitefields-ITOPS');
        g_form.addOption('building''WTC','Whitefields-Training Center');
    } else {
        g_form.removeOption('building''SC');
        g_form.removeOption('building''DLF1');
        g_form.removeOption('building''DLF2');
        g_form.removeOption('building''WPB');
        g_form.removeOption('building''ITOPS');
        g_form.removeOption('building''WTC');
        g_form.addOption('building''CKPA','CKP Block A');
        g_form.addOption('building''CKPB','CKP Block B');
}
}

Hi ,

 

I am trying to achieve a similar requirement, I am able to do it. However, the value is setting to the first option provided using addOption() and I am not able to change values later on. Is it an expected behavior?

How can we let user change option when we have added it addOption()? 

Thanks in advance.