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

My bad but that works both the way.

But it is nothing to do with my current issue.

I have put this "var reqtype = g_form.getValue("req_type");" and tried no luck with my current issue

 

Regards,
Sathish

sathishsk
Mega Guru

Hi All,

 

This works in the catalog item view by the way, if that helps.

 

Thanks & Regards,
Sathish

Check options on your Client script for this to work on RITM and CTASKS?

Or where else are you expecting this to work on??

 Applies on Requested Items

Applies on Catalog Tasks

 


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Hi Prateek,

As I mentioned before this works on catalog item view(service-now.com/com.glideapp.servicecatalog_cat_item_view.do)

find_real_file.png

but the same script doesn't work on service portal(service-now.com/ssp?id=sc_cat_item).

find_real_file.png

 

 

Regards,
Sathish

 

Are you sure that you are removing choice list values and not labels with g_form.removeOption() method?

 




Regards,
Sachin