g_form.removeOption is not working in service portal but the same works for catalog item view

sathishsk
Mega Guru

Hi All,

g_form.removeOption is not working in service portal for some reason.

I want to remove some option on the dropdown2 based on the selection of dropdown1.

unfortunately g_form.removeOption is not working and as a result I am seeing all the values in the dropdown2.

Can anyone suggest where I am going wrong here?

 

Thanks & Regards,

Sathish

1 ACCEPTED SOLUTION

ccajohnson
Kilo Sage

You may want to consider not using the removeOption method all together, and go with building the menus for each choice from newValue. I have done something similar and structured it a bit differently:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    if (newValue == '') {
        g_form.clearOptions('ipad_color');
        g_form.addOption('ipad_color', '', '-- None --', 0);
        return;
    }
    g_form.setValue('ipad_color', '');
    g_form.clearOptions('ipad_color');
    g_form.addOption('ipad_color', '', '-- None --', 0);
    if (newValue == 'mini_2') {
        g_form.addOption('ipad_color', 'silver', 'Silver', 1);
        g_form.addOption('ipad_color', 'space_gray', 'Space Gray', 2);
    }
    if (newValue == 'air_2' || newValue == 'mini_4') {
        g_form.addOption('ipad_color', 'gold', 'Gold', 1);
        g_form.addOption('ipad_color', 'silver', 'Silver', 2);
        g_form.addOption('ipad_color', 'space_gray', 'Space Gray', 3);
    }
    if (newValue == 'pro_97' || newValue == 'pro_129') {
        g_form.addOption('ipad_color', 'gold', 'Gold', 1);
        g_form.addOption('ipad_color', 'rose_gold', 'Rose Gold', 2);
        g_form.addOption('ipad_color', 'silver', 'Silver', 3);
        g_form.addOption('ipad_color', 'space_gray', 'Space Gray', 4);
    }
}

With this example, I am clearing all the options and setting the first option to be -- None -- if newValue is blank. Unclear if you are using -- None -- as a choice, but that is why it is there.

Then I set the value of the menu to be built with nothing, then clear all of the options.

Then I check the value of newValue (this is the same as your req_type variable) and process from there. I add a number to indicate the choice order to make things easy.

Feel free to model after this with your code and let us know if this is more successful.

View solution in original post

16 REPLIES 16

ccajohnson
Kilo Sage

You may want to consider not using the removeOption method all together, and go with building the menus for each choice from newValue. I have done something similar and structured it a bit differently:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    if (newValue == '') {
        g_form.clearOptions('ipad_color');
        g_form.addOption('ipad_color', '', '-- None --', 0);
        return;
    }
    g_form.setValue('ipad_color', '');
    g_form.clearOptions('ipad_color');
    g_form.addOption('ipad_color', '', '-- None --', 0);
    if (newValue == 'mini_2') {
        g_form.addOption('ipad_color', 'silver', 'Silver', 1);
        g_form.addOption('ipad_color', 'space_gray', 'Space Gray', 2);
    }
    if (newValue == 'air_2' || newValue == 'mini_4') {
        g_form.addOption('ipad_color', 'gold', 'Gold', 1);
        g_form.addOption('ipad_color', 'silver', 'Silver', 2);
        g_form.addOption('ipad_color', 'space_gray', 'Space Gray', 3);
    }
    if (newValue == 'pro_97' || newValue == 'pro_129') {
        g_form.addOption('ipad_color', 'gold', 'Gold', 1);
        g_form.addOption('ipad_color', 'rose_gold', 'Rose Gold', 2);
        g_form.addOption('ipad_color', 'silver', 'Silver', 3);
        g_form.addOption('ipad_color', 'space_gray', 'Space Gray', 4);
    }
}

With this example, I am clearing all the options and setting the first option to be -- None -- if newValue is blank. Unclear if you are using -- None -- as a choice, but that is why it is there.

Then I set the value of the menu to be built with nothing, then clear all of the options.

Then I check the value of newValue (this is the same as your req_type variable) and process from there. I add a number to indicate the choice order to make things easy.

Feel free to model after this with your code and let us know if this is more successful.

Hi John,

 

This fixed my issue, thanks for your help.

Thanks