Option "-- None --" is not appearing onChange
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2021 08:51 AM
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');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2021 08:53 AM
use below solution
https://community.servicenow.com/community?id=community_question&sys_id=85608e91dbfbd7805ed4a851ca961991
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2021 09:14 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2021 10:05 AM
Tried that and it didnt work

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2021 10:55 AM
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
Thanks
Anil Lande