Option "-- None --" is not appearing onChange

mkdj12
Giga Contributor

I'm using this onChange script to toggle what options are accessible from this select box variable. But for some reason the only option that doesn't appear is "-- None --". The field always selects the first option by default which is breaking other logic within the form. I've attempted to check the option on the variable to "include none" but that hasn't worked either. 

 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == '') {
       return;
    }
    var topic = g_form.getValue('topic_of_request');
    if (topic == "brand_storytelling") {
        g_form.clearOptions('category');
        g_form.addOption('category', 'none', '-- None --');
        g_form.addOption('category', 'campaign', 'Campaign');
        g_form.addOption('category', 'menu', 'Menu');
        g_form.addOption('category', 'customer_comment', 'Customer Comment');

    } else if (topic == "issues_management") {
        g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --');
        g_form.addOption('category', 'disaster_crisis', 'Disaster/Crisis');
        g_form.addOption('category', 'food_safety', 'Food Safety');
        g_form.addOption('category', 'supply_chain', 'Supply Chain');
        g_form.addOption('category', 'diversity_inclusion', 'Diversity & Inclusion');
        g_form.addOption('category', 'political_social_cause', 'Political or Social Cause');
    } else {
        g_form.clearOptions('category');
    }
}

 

10 REPLIES 10

sachin_namjoshi
Kilo Patron
Kilo Patron

use below solution

 

https://community.servicenow.com/community?id=community_question&sys_id=85608e91dbfbd7805ed4a851ca961991

 

Regards,

Sachin

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

What happens if you add this at the end of addOption

g_form.setValue('category', '');

 

PS: make sure that the valie fir '--None--' is '' (blank) and not 'none'

-Anurag

-Anurag

Tried that and it didnt work

Hi,

Are you sure that you have only one client script running on your form?

There is a possibility of another script overriding the options .

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande