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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Hide multi selctoptionSet on form using Java Script

(0) ShareShare
ReportReport
Posted on by 160

Hi all,

I want to hide a multi Selectoptionset on account form. The reqirement is, wenn another two optionset field on this form set to a Value (e.g. ja), then change the visibility of Multi optionset to false.

I have used this Code on the field properties of my Two option set On change, but i cant understand why it doesnt work :

function toggleMultiSelectVisibility (executionContext) {

        var formContext = executionContext.getFormContext(); // get formContext
        
        if (formContext.getAttribute('pb_type').getValue() === "ja" {        
            formContext.getControl("pb_testmultiselectoptionset").setVisible(false);
        }    
        else {
            formContext.getControl("pb_testmultiselectoptionset").setVisible(true);        
        }

Does anybody have any idea?

Many Thanks in advance

I have the same question (0)
  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Update your code as below and check.

    function toggleMultiSelectVisibility (executionContext) {

           var formContext = executionContext.getFormContext(); // get formContext

           if (formContext.getAttribute('pb_type').getText() === "ja" {        

               formContext.getControl("pb_testmultiselectoptionset").setVisible(false);

           }    

           else {

               formContext.getControl("pb_testmultiselectoptionset").setVisible(true);        

           }

    }

    Please mark my answer verified if i were helpful

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Elpibato,

    The following code has some question:

    pastedimage1598319359345v1.png

    1.If() condition lack right brackets ‘)’

    2.”ja” is text of two optionset field, you need use getText() function, or set correct value instead of “ja”.

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Also please see below article to set multioption field value from javascript

    balugajjala.wordpress.com/.../

    It is always a good practice to debug your code to know what is happening. 

    Please mark my answer verified if i were helpful

  • Elpibato Profile Picture
    160 on at

    Thanks for your answer,

    I put your code in Text Editor, but I get in form an error when i change the two option set field:

    Web resource method does not exist: toggleMultiSelectVisibility

    Do you have any idea what could cause this error?

    Regards

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Elpibato,

    You can upload your JavaScript file (.js) to your web resource, because there might be an issue with it if you used the Text Editor option.

    pastedimage1598348823947v1.png

    When you set onChange event, you need ensure function name is right and check ‘Pass execution context as first parameter’

    pastedimage1598348834217v2.png

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Elpibato Profile Picture
    160 on at

    Thank you!

    it works now!

    Best regards

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans