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

PGhate
Tera Guru

Checkout Using the g_form.addOption method - Support and Troubleshooting (servicenow.com)

I have used g_form.addOption('field value', '' , '-- None --');  and it worked for me.