web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Visibility based on value selected in multi-select field not working

(0) ShareShare
ReportReport
Posted on by 70

Hi,

I have a multi-select choice field and based on the value selected from that field, I want to show/hide another field. So I want to show another field only if a particular value is selected from the dropdown. Here is the code I wrote, but its not working. So can you please tell me what is wrong with my code...

function hideFieldsReviewer(executionContext) {
var formContext = executionContext.getFormContext();
var agencytypecodevalue = formContext.getAttribute(“new_agencypersontypecode”).getValue();

if (agencytypecodevalue != null && agencytypecodevalue != 248870016 ) {
formContext.getControl(“new_reviewertype”).setVisible(false);

}

else {
formContext.getControl("new_reviewertype”).setVisible(true);
}

}

Thanks!

I have the same question (0)
  • D365 User 06 Profile Picture
    70 on at
    RE: Visibility based on value selected in multi-select field not working

    I have revised the above code and updated it, but the updated code is also not working. Please find below the updated code...

    function onMultiSelectChange(executionContext) {

       var formContext = executionContext.getFormContext();

       var moField = formContext.getAttribute(“new_agencypersontypecode”);

       var selectedOptions = moField.getSelectedOption();

       if(selectedOptions != null){  

       if(selectedOptions.filter(i => i.value  != 248870016).length > 0) {

           formContext.getControl(“new_reviewertype”).setVisible(false);

       } else {

           formContext.getControl(“new_reviewertype”).setVisible(true);

       }

    }

    if(selectedOptions == null){

           formContext.getControl(“new_reviewertype”).setVisible(false);

    }

    }

  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: Visibility based on value selected in multi-select field not working

    Hi,

    It should work. Can you please share screenshot of your optionset field values to confirm if value mentioned in your js code is correct.

    Can you also check as below

    if(selectedOptions.filter(i=>i.value===248870016).length>0)

    {

    Show field

    }

    else

    {

    Hide field

    }

  • Suggested answer
    Yuri ji Profile Picture
    on at
    RE: Visibility based on value selected in multi-select field not working

    Hi,

    When I copied your code into “VS Code”, your quotation marks were not English characters.

    5140.png

    After I corrected and tested the code, I found that it works.

    Match “else” condition.

    pastedimage1663220502932v1.png

    Match “if” condition.

    pastedimage1663220532604v2.png

    Match “if(null)” condition.

    pastedimage1663220556312v3.png

  • MuhammadAnas Profile Picture
    15 on at
    RE: Visibility based on value selected in multi-select field not working

    Why don't use Business? I think it is a good approach.

  • Suggested answer
    D365 User 06 Profile Picture
    70 on at
    RE: Visibility based on value selected in multi-select field not working

    Bipin Kumar 

    Thank you for your response. I tried replacing != with === which partly rectified my code, but still it wasnt working so I tried putting the value portion in brackets and wierdly it seemed to work!

    This was my updated version :-

    if(selectedOptions.filter(i => (i.value == 248870016)).length > 0) {

    Thanks for your help! I'm marking your answer as Suggested Answer as it partly solved my problem.

  • Suggested answer
    D365 User 06 Profile Picture
    70 on at
    RE: Visibility based on value selected in multi-select field not working

    Yuri ji

    Thank you for your response. Yes you are right, there is something off about those quotes which seems to have caused an error. I have rectified it, and have also realized that the main problem in my code existed in this line, which I have updated and now my code seems to be working fine…

    if(selectedOptions.filter(i => (i.value == 248870016)).length > 0) {

    Thanks for your help! I'm marking your answer too as Suggested Answer as you pointed out the error in those quotes.

  • D365 User 06 Profile Picture
    70 on at
    RE: Visibility based on value selected in multi-select field not working

    Business Rules doesnt work for Multi-Select Choice fields.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 109

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 109

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 71 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans