Objective : I have 2 option sets(Gender and Hobbies).
So based on the Gender selection i want to show/hide options in my option set hobbies.
// JavaScript source code
function check() {
var gender = Xrm.Page.getAttribute('hhh_gender').getSelectedOption().value;
var RoleSubCategoryOptionSet = Xrm.Page.ui.controls.get('hhh_hobbies');
RoleSubCategoryOptionSet.clearOptions();
for (var i = 0; i < RoleSubCategoryOptionSet.length; i++) {
// get control name stored in the array element.
var att = RoleSubCategoryOptionSet[i];
// set the control value to null to make it clear.
Xrm.Page.getattribute(att).setvalue(null);
}
if (gender != null) {
if (gender = 1) {
RoleSubCategoryOptionSet.clearOptions();
//Xrm.Page.getControl('hhh_hobbies').removeOption(2);
//Xrm.Page.getControl('hhh_hobbies').removeOption(3);
Xrm.Page.getControl('hhh_hobbies').addOption('Sports',1);
Xrm.Page.getControl('hhh_hobbies').addOption('Dancing',4);
}
else if (gender = 2) {
RoleSubCategoryOptionSet.clearOptions();
//Xrm.Page.getControl('hhh_hobbies').removeOption(1);
//Xrm.Page.getControl('hhh_hobbies').removeOption(4);
Xrm.Page.getControl('hhh_hobbies').addOption('Cooking',2);
Xrm.Page.getControl('hhh_hobbies').addOption('Singing',3);
}
else {
alert("Select option sir.");
}
}
}
Getting error :
Required parameter is null or undefined: optionSetItem.value.