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

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.

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    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

  • Suggested answer
    dynamicallyndsey Profile Picture
    10 on at

    Thank you so much Leah!

  • Community Member Profile Picture
    on at

    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!:) 

  • karthikt29 Profile Picture
    3 on at
    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.

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 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

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

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans