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

Announcements

News and Announcements icon
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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Hamza H Profile Picture

Hamza H 140 Super User 2026 Season 1

#2
Nagaraju_Matta Profile Picture

Nagaraju_Matta 128

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans