Remove options from a form on Service Portal (g_form.removeOption() trouble)

Student1
Tera Contributor

Hello all, I need some assistance to the following requirement.

I have a record producer on SP, where depending on the category selection, only related subcategories are visible.

For instance, for the category "hardware", only the following subcategories are visible.

find_real_file.png

However, if I change to another category (for example "software"), all the options are not visible (only the option "--None--" is visible). Then, if I return back to the category "hardware", all the previous options (shown on the first image) are not visible any more as shown below.

find_real_file.png

I am using a Catalog Client Script (onChange), that gets the value of the field category, and based on that value removes all the unrelated options on the subcategory field. My script looks like this:

find_real_file.png

Any assistance would be really helpful. 

Thank you all in advance.

 

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Try using format as below

g_form.removeOption('variable_name','value','label');

So, 

g_form.removeOption('subcategory','11','CPU'); //suppose 11 is value while CPU is label.

 

In addition, you need to use g_form.addOption() as well. So, for  your case suppose 

if(cat==8)

{

g_form.removeOption('subcategory','11','CPU');

..

g_form.addOption('subcategory','7'); //choice you want to show

...

}

 

So, for every .removeOption() you need to use .addOption() to add & make it work independently.

View solution in original post

6 REPLIES 6

No problem. All the best to your learning.

Good info Jaspal.

I found that by adding the value and label ONLY to the removeOption worked great, however, I'd have a blank space below my choice list. Weird.

So I also added the value and label to the addOption function and it worked great.

 

This is in Vancouver