Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Working with lookup fields.

(0) ShareShare
ReportReport
Posted on by 106

Hi all, i am having to implement something which i am going to type out.
So i have 'Account Name', 'Division Name', Class Number and Class Name(Order is important).

Account Name and Division Name are basically OOB Account Entity Lookup fields whereas Class Number and Class Name are text fields.
Step 1 - Select an Account 'A'. This should give me the options in Division Name Lookup to select only those 'divisions' which belong to the selected Account 'A'.
Step 2 - Select Division Name 'X'. This should populate Class Numbers and Class Names under that division 'X'.

Edit : 1) Account Name and Division Name are basically OOB Account Entity Lookup fields

  • KashyapT Profile Picture
    106 on at
    RE: Working with lookup fields.

    121212.png

    [quote user="Lu Hao"]

    Hi partner,

    First, on which entity's form are there the two lookup fields?

    This should give me the options in Division Name Lookup to select only those 'divisions' which belong to the selected Account 'A'.

    So is there a subgrid of divisions(Account) in the Account entity?

    This should populate Class Numbers and Class Names under that division 'X'.

    How to populate Class Numbers and Class Names? What is the rule of populating?

    [/quote]

    Also, onChange of Division Name in 2nd Tab i have this code :
    function func(executionContext)
    {
    var formContext = executionContext.getFormContext();
    var dname = formContext.getAttribute('new_divisionname');
    var dnameValue = dname.getValue();
    var classNameOptionSet = formContext.getControl('new_classname');
    var classNumberOptionSet = formContext.getControl('new_classnumber');
    if( dnameValue != null )
    {
        var dnameGUID = dnameValue[0].id;
        Xrm.WebApi.online.retrieveRecord("account", dnameGUID, "?$select=new_classname2,new_classname3,new_classname4,new_classnumber2,new_classnumber3,new_classnumber4").then(
        function success(result) {
              var ClassName2 = result['new_classname2'];
              var ClassName3 = result['new_classname3'];
              var ClassName4 = result['new_classname4'];
              var ClassNumber2 = result['new_classnumber2'];
              var ClassNumber3 = result['new_classnumber3'];
              var ClassNumber4 = result['new_classnumber4'];
              if (classNameOptionSet == null || classNameOptionSet != null) {
                            var obj1 = {};
                            obj1['text'] = ClassName2;
                            obj1['value'] = 10;
                            classNameOptionSet.addOption(obj1);//add to option set field
                            var obj2 = {};
                            obj2['text'] = ClassName3;
                            obj2['value'] = 11;
                            classNameOptionSet.addOption(obj2);//add to option set field
                            var obj3 = {};
                            obj3['text'] = ClassName4;
                            obj3['value'] = 12;
                            classNameOptionSet.addOption(obj3);//add to option set field
                }
              if (classNumberOptionSet == null || classNumberOptionSet != null) {       
                           var obj4 = {};
                            obj4['text'] = ClassNumber2;
                            obj4['value'] = 13;
                            classNumberOptionSet.addOption(obj4);//add to option set field
                            var obj5 = {};
                            obj5['text'] = ClassNumber3;
                            obj5['value'] = 14;
                            classNumberOptionSet.addOption(obj5);//add to option set field
                            var obj6 = {};
                            obj6['text'] = ClassNumber4;
                            obj6['value'] = 15;
                            classNumberOptionSet.addOption(obj6);//add to option set field
                }
             
              },
        function (error) {
               Xrm.Utility.alertDialog(error.message);
             }
          );
    }
    else
    var clear = formContext.getControl('new_classname').clearOptions();
    var clearIt = formContext.getControl('new_classnumber').clearOptions();
    }

     And this is throwing an error saying "One or more of the option values for this picklist are not in the range of allowed values."
    Error code: 0x8004431a., when i select an option and save. If i dont select an option and save there is no error being thrown.

  • KashyapT Profile Picture
    106 on at
    RE: Working with lookup fields.

    I have a custom entity called "Client" in which there are the above 2 lookup fields.

    No, there is no sub grid of divisions(Account) in account entity.

    Class number and Class Name are just empty option sets which i populate and clear on lookup selection/deselection.

  • LuHao Profile Picture
    40,886 on at
    RE: Working with lookup fields.

    Hi partner,

    First, on which entity's form are there the two lookup fields?

    This should give me the options in Division Name Lookup to select only those 'divisions' which belong to the selected Account 'A'.

    So is there a subgrid of divisions(Account) in the Account entity?

    This should populate Class Numbers and Class Names under that division 'X'.

    How to populate Class Numbers and Class Names? What is the rule of populating?

  • KashyapT Profile Picture
    106 on at
    RE: Working with lookup fields.

    Account Name and Division Name are lookup to the same OOB Account entity.

  • LuHao Profile Picture
    40,886 on at
    RE: Working with lookup fields.

    Hi partner,

    Could you elaborate on your needs?

    What is the relationship between the Account entity and the Division entity?

    According to Step 1, there is a 1:N relationship between Account and Division.

    According to Step 2, there is an N:1 relationship between Account and Division.

    If you provide some screenshots this will help us better understand your problem.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 149 Super User 2025 Season 1

#2
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 53 Super User 2025 Season 1

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 32 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans