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.

  • CU16080530-3 Profile Picture
    CU16080530-3 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.

  • 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
    dynamicallyndsey 10 on at
    RE: Multi-select Option Set field - Set a maximum number of choices

    Thank you so much Leah!

  • Verified answer
    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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February 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... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans