web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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

I have the same question (0)
  • Verified answer
    Drew Poggemann Profile Picture
    4 on at

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

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

  • Victor Onyebuchi Profile Picture
    410 on at

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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans