Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Hide multi selctoptionSet on form using Java Script

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

  • Elpibato Profile Picture
    Elpibato 160 on at
    RE: Hide multi selctoptionSet on form using Java Script

    Thank you!

    it works now!

    Best regards

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Hide multi selctoptionSet on form using Java Script

    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
    Elpibato 160 on at
    RE: Hide multi selctoptionSet on form using Java Script

    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
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Hide multi selctoptionSet on form using Java Script

    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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Hide multi selctoptionSet on form using Java Script

    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
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Hide multi selctoptionSet on form using Java Script

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans