Remove option and add option is not working

Niharika14
Tera Contributor

Hi all,

 

The requirement here is to remove option L2 support subcategory when the category is Process Knowledge/System Questions and country is other than Korea , Vietnam , Japan, Thailand. I have written an on change catalog client script which works on change of category . But add option and remove option lines are not working though it is going inside the loop. Please help me out in this. Below is the script for the same.

 

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

}

var country_name = g_form.getValue('u_country');
g_form.addInfoMessage(country_name);
g_form.clearOptions('subcategory');

if (country_name != 'KR' && country_name != 'VN' && country_name != 'TH' && country_name != 'JP') {
if (newValue == "Process Knowledge/System Questions") {
g_form.addInfoMessage(country_name);
g_form.addInfoMessage("1");
g_form.removeOption('subcategory', 'L2 Support');
}
} else {
g_form.addOption('subcategory', 'L2 Support', 'L2 Support');
g_form.addInfoMessage('55');
}

}

10 REPLIES 10

Samaksh Wani
Giga Sage
Giga Sage

Hello @Niharika14 

 

addOption(String fieldName, String choiceValue, String choiceLabel)

Adds a choice to the end of a choice list field.
Parameters
Name Type Description
fieldNameStringThe name of the field.
choiceValueStringThe value to be stored in the database.
choiceLabelStringThe value displayed.

 

removeOption

 

g_form.removeOption(<fieldName>, <choiceValue>);

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

Samaksh Wani
Giga Sage
Giga Sage

Hello @Niharika14 

 

In your case :- g_form.addOption('subcategory', 'L2 Support', 'L2 Support'); 

 

, pls check the backend value of L2 Support using Show XML and give it in third param. Same as for removeOption.

 

 

Hi Samaksh,

 

Backend value is correct only. The same script is working absolutely fine on change of country.

 

 

Hello @Niharika14 

 

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.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh