Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Having issues hiding/showing options in an option set based on the option selection in another option set.

(0) ShareShare
ReportReport
Posted on by 104

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.

  • cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Having issues hiding/showing options in an option set based on the option selection in another option set.

    Hi Kashyap,

    Could it solve your problem?

    Regards,

    Clofly

    Please kindly mark as verified if you had found any answer helped, it would be really appreciated.

  • Mayank Pujara Profile Picture
    Mayank Pujara 830 on at
    RE: Having issues hiding/showing options in an option set based on the option selection in another option set.

    please look at following example for this..

    https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg594433(v=crm.8)?redirectedfrom=MSDN

    http://crmoptionsets.azurewebsites.net/

  • Suggested answer
    ba365guy Profile Picture
    ba365guy 2,948 on at
    RE: Having issues hiding/showing options in an option set based on the option selection in another option set.

    .addOption(option, index)

    In the above method, "option" is an object with two parameters:

    text: String. The label for the option.
    value: Number. The value for the option.

    Index is separate optional parameter.

    I think you got error because you did not use the method correctly.

  • Suggested answer
    cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Having issues hiding/showing options in an option set based on the option selection in another option set.

    Hi Kashyap,

    You should pass object into addOption function if you would like to add an option to optionset.

    Xrm.Page.getControl("hhh_hobbies").addOption({value: 1, text: 'Sports'});

    API Reference:

    https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg334266(v=crm.8)?redirectedfrom=MSDN#addoption

    Demo:

    https://itsfascinating.com/d365/tag/addoption/

    pastedimage1579595308792v1.png

    Regards,

    Clofly

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans