Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to access a specific value of a lookup field via service client - early bound classes

(0) ShareShare
ReportReport
Posted on by 410

Hello People,

   I have been trying to access a specific follow of a lookup field, I am kind of new to Dynamic CRM, so my code might be a bit off. My coe is below. Thanks 

//var orgContext = new MedinetCRMService(GetOrgService());

                new_hospital hospital = new new_hospital();
                hospital.new_AddressOne = HAddressTextBox.Text.ToString();
                hospital.new_name = HNameTextBox.Text.ToString();

            Account trust = new Account();
            QueryExpression trustQuery = new QueryExpression();
            trustQuery.EntityName = "account";
            trustQuery.ColumnSet = new ColumnSet("name");
            trustQuery.Criteria.AddCondition(trust.Name, ConditionOperator.Equal, "BIRMINGHAM TRUST");

            Guid accountid = Guid.Empty;
            string accountName = "";
            EntityCollection Collection = Service().RetrieveMultiple(trustQuery);
            foreach (Account account in Collection.Entities)
            {
                accountid = account.Id;
               accountName = account.GetAttributeValue<string>("name");
            }


            
            //Account account = (Account)GetOrgService().Retrieve(trust.LogicalName, trustID, new Microsoft.Xrm.Sdk.Query.ColumnSet("name"));
            CrmEntityReference trustid = new CrmEntityReference(trust.LogicalName, accountid);
            hospital.new_OwningTrustId = trustid;
            Service().Create(hospital);
            MessageBox.Show("succesfully added a hospital record");

I know, I am not meant to use retrieveMultiple at the first place. Thanks in advance

*This post is locked for comments

  • Victor Onyebuchi Profile Picture
    410 on at
    RE: How to access a specific value of a lookup field via service client - early bound classes

    Thanks Drew, Microsoft have a way in complicating simple code, but this helped.

  • Verified answer
    Drew Poggemann Profile Picture
    4 on at
    RE: How to access a specific value of a lookup field via service client - early bound classes

    Hi Victor, the following provides a very detailed example for you to follow, hopefully this helps!

    msdn.microsoft.com/.../dn879513(v=mdm.8).aspx

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 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…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans