Unable to remove subcategory choice value based on category choice value selection.

mmr
Tera Contributor

We are trying to remove choice value(ex: test) from subcategory when we select a choice value(ex: test1) on Category field. We have tried with onChange client script by using the g_form.removeOption method, but it is not working as there was already a dependent checkbox checked for the subcategory field in the dictionary.

Any suggestion would be helpful for us.

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

If you are using dependent field then no need to use onchange script

Regards

Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

   

   If it is not a dependent field, how to clear the sub category value based on category removal. I have created two list collector variable for the category and sub category.

This is incorrect.  You may only want to show a subcategory field to a certain group of users.
He has a perfectly legitimate use case.

Sajilal gave the correct answer.
Check out my Consultant's Survival Guide
https://youtube.com/watch?v=zYi8KhP9SUk

Hi Ankur,

I have one requirement for which i am facing problem to achieve this, i need to remove certain options from the subcategories on the portal for the incident record producer, below is the script i created but seems not to be working 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
var incident_category = g_form.getValue('category');
if(incident_category == 'infra')
{
g_form.removeOption('subcategory', 'provision');

g_form.removeOption('subcategory', 'crm');
}
}

 can you please help me why this is not working, is this anything related to the dependent field we are using on record producer which is conflicting? 
how can i achieve this?