removeOption and addOption not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 11:00 PM
Hi,
I need to remove the choice list values of the "subcategory" field which is dependent on "category" field.
Client script: Onload()
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var getGroup,getCat,getSubCat;
getGroup = g_form.getValue('assignment_group');
alert("getGroup: " + getGroup);
if(getGroup == 'e717093b786b5c00910063ad31c0bff5')
{
getCat = g_form.getValue('category');
alert("getCat: " + getCat);
if(getCat == 'Application')
{
alert("Inside if of Application");
g_form.removeOption('subcategory', 'MS Office');
g_form.removeOption('subcategory', 'Teams');
g_form.removeOption('subcategory', 'Outlook (email)');
}
if(getCat == 'Hardware')
{
alert("Inside if of Hardware");
g_form.removeOption('subcategory','Handheld wireless device');
g_form.removeOption('subcategory','Laptop');
g_form.removeOption('subcategory','Workstation');
}
if(getCat == 'Network')
{
alert("Inside if of Network");
g_form.removeOption('subcategory','Wireless');
}
if(getCat == 'Software')
{
alert("Inside if of Software");
g_form.removeOption('subcategory','Driver');
g_form.removeOption('subcategory','MS Office');
g_form.removeOption('subcategory','Infopath');
g_form.removeOption('subcategory','RMS');
}
}
else
{
getCat = g_form.getValue('category');
if(getCat == 'Application')
{
alert("Inside if of Application when group changes");
g_form.addOption('subcategory', 'MS Office');
g_form.addOption('subcategory', 'Teams');
g_form.addOption('subcategory', 'Outlook (email)');
}
if(getCat == 'Hardware')
{
alert("Inside if of Hardware when group changes");
g_form.addOption('subcategory','Handheld wireless device');
g_form.addOption('subcategory','Laptop');
g_form.addOption('subcategory','Workstation');
}
if(getCat == 'Network')
{
alert("Inside if of Network when group changes");
g_form.addOption('subcategory','Wireless');
}
if(getCat == 'Software')
{
alert("Inside if of Software when group changes");
g_form.addOption('subcategory','Driver');
g_form.addOption('subcategory','MS Office');
g_form.addOption('subcategory','Infopath');
g_form.addOption('subcategory','RMS');
}
}
}
All the alerts are working fine as per the above condition.
REF::
I don't see the removeOption and addOption to be working.
Any help?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 11:07 PM
Hi
Please look at the docs here -
https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_GlideFormRemoveOption_String_String
I see you have not used it properly.
Hope this helps.
Regards
Omkar Mone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 11:53 PM
Hi,
The code is just fine. The only changes that was to be done was in the addOption to add the label value.
Even after that no luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2019 12:11 AM
Hi Hemanth,
Since you said your subcategory is dependent on category field; possibly that might be blocking from adding/removing the options
It seems you are trying to populate subcategory based on category in your script; can you try to remove the subcategory as dependent field on category and check once
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2019 01:58 AM
Hi Ankur,
Can't this be done without removing the dependency field? If we remove it i am able to see that the removeOption and addOption is working fine.
But removing the dependency field will lead to display all the subcategory of the dependent field of all the categories.