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 :
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

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans