Skip to main content

Notifications

Community site session details

Community site session details

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

Multi-select Option Set field - Set a maximum number of choices

(1) ShareShare
ReportReport
Posted on by 10

Hello!

Anyone know if it is possible to enforce a maximum number of choices on multi-select option sets? 

Ideally, we would like a multi-select option set field on a form but only allow a maximum of 2 choice selections.

  • CU16080530-3 Profile Picture
    3 on at
    Multi-select Option Set field - Set a maximum number of choices
    Hi, The answer on this post is very helpful, but I am also looking to limit it to only two options instead of setting the value to null. Is there a way to deselect the third option and show only two options onColumnChange

    I already tried 

    multiSelect.setValue(selectedOptions.slice[0,2]);

    but the above don't work sometimes, in fact many times.

  • Community Member Profile Picture
    on at
    RE: Multi-select Option Set field - Set a maximum number of choices

    Hi Partner,

    Can you click Yes under "Did this answer your question?" to close this thread if my answer is helpful.

     pastedimage1638752028089v1.png

    Thanks in advance!:) 

  • Suggested answer
    dynamicallyndsey Profile Picture
    10 on at
    RE: Multi-select Option Set field - Set a maximum number of choices

    Thank you so much Leah!

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Multi-select Option Set field - Set a maximum number of choices

    Hi Partner,

    You need use js code to enforce a maximum number of choices on multi-select option sets in the form.

    JS:

    function maximumNumber(executionContext) {
        var formContext = executionContext.getFormContext();
        var multiSelect = formContext.getAttribute("new_intendedproductusers");// get multi-select option sets field

        var selectedOptions = multiSelect.getSelectedOption();
        if (selectedOptions != null) {
            if (selectedOptions.length > 2) {
                alert("only allow a maximum of 2 choice selections");
                multiSelect.setValue(null);
            }
        }
    }

    Go Settings > Customizations > Customize the system >  Web Resource to add new:

    pastedimage1638495740798v1.png

    Go Settings > Customizations > Customize the system > Entities > One entity you need > Forms to open one main form you need.

    pastedimage1638495988876v3.png

    pastedimage1638495955841v2.png

    Save and publish all customizations.

    Test:

    pastedimage1638496628583v4.png

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March 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... 294,017 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,852 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans