Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Create field dependencies

(0) ShareShare
ReportReport
Posted on by 5

Hi everyone,

I'm new to Dynamics so please don't be too judgy.

I have a problem with creating a dependency between two fields. The objective is:

I have two option set fields - A and B. In field A I can choose from option A1 and A2. In field B I can choose from option B1 to B6.
The option I can choose in field B should depent on the option I select in field A. I give you an example:

If A1 is selected, I can only select B1, B2 and B3.
If A2 is selected, I can only select B4, B5 and B6.

Is this possible just with configuring the fields and the form? Is some kind of table necessary and if yes how do I integrate it in my form?

I hope my question is understandable.

Thank you!

  • DerAnwender Profile Picture
    DerAnwender 5 on at
    RE: Create field dependencies

    I missed the option in the properties until I updated the form "main" in B by including entity A.

    Sry, if you described this. I don't unterstand Dynamics too well yet.

    Thank you all for your help.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create field dependencies

    If you open the lookup field for B on the form that needs B to filter, there is a related records filter you can use, like the image below.

    pastedimage1616515048490v1.png

  • DerAnwender Profile Picture
    DerAnwender 5 on at
    RE: Create field dependencies

    Hi Mehdi,

    thank you very much for your answer.

    I have to admit, your solution is a bit too complicated for me.

    I try Mike Hastings suggestion but I appreciate your effort.

    Thank you for your enormous support!

  • DerAnwender Profile Picture
    DerAnwender 5 on at
    RE: Create field dependencies

    Hi Mike,

    thank you very much, you answers helps me a lot.

    I configured the entities and lookup fields like you described it but in can't find where to set up the filter for B based on what I select on A.

    Do I use a business rule or do I configure the lookup field properties in the form?

    Again, thank you!

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Create field dependencies

    Hello, 

    First, welcome to the Dynamics community. All questions are more than welcome, we are all here to learn and share our knowledge. 

    It is possible to implement your scenario using JavaScript code as the field type used is OptionSet. We could have implemented your scenario with a simple configuration if the Field type were a LookUp.

    I implement a generic method using JavaScript Code that you can use for every two dependents OptionSets. 

    if(typeof(MEA)=="undefined"){MEA={}};
    if(typeof(MEA.OptionSet)=="undefined"){MEA.OptionSet={}};
    if(typeof(MEA.OptionSet.Utilities)=="undefined"){MEA.OptionSet.Utilities={}};
    
    MEA.OptionSet.Utilities = {
        //Cascading Utility
        optionSetBValues : null,
        Cascade: function (executionContext, optionAName, optionBName, dependecies) {
            var formContext = executionContext.getFormContext();
            var selectedAValue = formContext.getAttribute(optionAName).getValue();
            var optionSetBControl = formContext.getControl(optionBName);
    
            if (optionSetBValues == null)
                optionSetBValues = optionSetBControl.getOptions();
    
            if (selectedAValue != null) {
                optionSetBControl.clearOptions();
                var dependeciesB = dependecies.find(d => d[0] == selectedAValue).slice(1);
                var filtredOptionB = optionSetBValues.filter(v => dependeciesB.includes(v.value));
                filtredOptionB.forEach(d => {
                    optionSetBControl.addOption(d);
                })
            }
            else {
                optionSetBControl.clearOptions();
            }
        }
    }


    Config: 

    OnLoad: 

    pastedimage1614350316274v1.png

    onChange : 

    pastedimage1614350389908v2.png

    Now, Let's take the following scenario:

    OptionA

    • schemaname: mea_optionacode.
    • options: 
      • label: A1, value: 1
      • label: A2, value: 2

    OptionB: 

    • schemaname: meaoptionbcode. 
    • options:
      • label: B1, value 1
      • label: B2, value 2
      • label: B3, value 3
      • label: B4, value 4 
      • label: B5, value 5 
      • label: B6, value 6

    If A1 is selected. Only B1, B2, B4 can be selected. 

    If A2 is selected. Only B3, B5, B6 can be selected. 

    The handler properties will be: 

    pastedimage1614351140353v3.png

    Comma separated list of parameters: 

    "mea_optionacode","mea_optionbcode",[[1,1,2,4,[2,3,5,6

    "mea_optionacode": optionA schemaName. 

    "mea_optionbcode": optionB schemaName. 

    [[1,1,2,4,[2,3,5,6: Array containing the dependecies: 

    • [1, 1, 2, 4: value 1 selected, only values 1, 2, 4 can be selected. 
    • [2, 3, 5, 6: value 2 selected, only values 3, 5, 6 can be selected. 

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,087 Super User 2024 Season 1 on at
    RE: Create field dependencies

    beside the suggestion to use entities instead optionset fields to handle this requirement (as Mike Hastings suggested), if you have already the optionset fields you can try my Dependent Option Set Manager (DOSM) solution

    demo: guidopreite.github.io/.../

    source: github.com/.../DOSM

    download: github.com/.../releases

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create field dependencies

    You have a few options - you can use javascript (but that would be outside of configuration)

    If you want to configure it, you can create two entities - A and B.  Create your A1 and 2 in entity A, then B1-6 in entity B.

    - Create a 1:N relationship from A to B, populate records B1, B2, and B3 with the lookup field to A1, do the same for the rest.  Now your data is setup.

    On the original entity (not A or B) make two lookup fields, one to A and one to B.  Then on the lookup field for to entity B you can filter based on the what is picked in lookup to entity A.

    Let me know if I confused you nd ill grab a screenshot.

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans