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 :
Service | Customer Service, Contact Center, Fie...
Suggested Answer

How to Create a Conditional Statement for fields that have multiple option sets

(0) ShareShare
ReportReport
Posted on by 32

I know how to create conditional statements but, i have some fields that are multiple option sets. 

In my mind i have this planned: 

If Product family equals this Product, then 6 options in this field are available to pick from
If Product family equals this different Product, then 4 options in same field from above are available to pick from
If Product family equals this different Product, then 2 options in same field from above are available to pick from
If Product family equals this different  Product, then 5 options in same field from above are available to pick from
pastedimage1586396841547v1.png
Right now the only options i have are : 
Flow - Condition
Actions - Recommendation, Unlock/lock, show error message, Set field value, Set Default value, Set business require, Set visibility 
Is this able to be done? If so please help. If i have to make more than one condition then that is fine.
 
I have the same question (0)
  • Suggested answer
    Denny Deng Profile Picture
    on at

    this should be easier to archive by using JS code register in form onload event

  • Suggested answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    There is no OOB way to do this, and Business Rule also doesn't support this condition.

    I recommend you to use JS code to enable this custom condition.

    For example, I have two fields on my form:

    Option base (option set)

    Label      Value

    A                1

    B                2

    Multiple condition(multiple option set)

    Label             Value

    Apple                1

    Banana             2

    Pear                  3

    Orange             4

    Now I want when I choose A in Option Base, only "Pear" and "Orange" are available in Multiple condition, when I choose B, only "Apple" and "Banana" available.

    So I created the following code with JS to archive this.

    function filterOptions(executionContext){
        var formContext=executionContext.getFormContext();
        var conditionValue=formContext.getAttribute("new_optionbase").getValue();
        var multipleField=formContext.getControl("new_multiplecondition");
        if(conditionValue!=null){
            //if we select A in conditionField
            if(conditionValue==1){
                multipleField.removeOption(1);
                multipleField.removeOption(2);
                //get current options in multiple options
                var currentOptions=multipleField.getOptions();
                if(!checkExisting(currentOptions,3)&&!checkExisting(currentOptions,4)){
                    multipleField.addOption({value:3,text:"Pear"});
                    multipleField.addOption({value:4,text:"Orange"});
                }
                
            }
            
            //if we select B in conditionField
            if(conditionValue==2){
                multipleField.removeOption(3);
                multipleField.removeOption(4);
                //get current options in multiple options
                var currentOptions=multipleField.getOptions();
            if(!checkExisting(currentOptions,1)&&!checkExisting(currentOptions,2)){
                multipleField.addOption({value:1,text:"Apple"});
                multipleField.addOption({value:2,text:"Banana"});
                }
            }
        }
    
    }
    
    function checkExisting(array, value) {
        var result = false;
        array.forEach(item => {
            if (item.value == value) {
                result = true;
            }
        })
        return result;
    }

    To avoid logical errors caused by repeated choices, I added some logical control codes.

    Add this function both in form onload event and Option Base onchange event.

    pastedimage1586416463425v2.png

    pastedimage1586416477089v3.png

    pastedimage1586416449884v1.png

    Save and publish.

    Let's see the results.

    When open a new creation form, there are 4 options in multiple condition in default.

    pastedimage1586416797707v4.png

    When we select A, then only show Pear and Orange.

    pastedimage1586416846107v5.png

    Select B, only show Apple and Banana.

    pastedimage1586420219351v6.png

    When you save the record and open it again, this rule is also enabled.

    pastedimage1586420386010v7.png

    Hope it helps.

    Best Regards,

    Leo

  • SeanaLee Profile Picture
    32 on at

    i am not familiar with JS coding. 

    Can i copy your code and and just insert my terms and fields?

  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    Yes, but you need to replace the field name and option set value  with your owns.

    And then just add the JS code into your instance, I provided the steps in my above reply.

    Regards,

    Leo

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 > Service | Customer Service, Contact Center, Field Service, Guides

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 55 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 27 Most Valuable Professional

#3
Soundari Profile Picture

Soundari 15

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans