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)

retrieve lookupID from the text and set the retrieved value

(0) ShareShare
ReportReport
Posted on by 590

HI Friends

REquirment:

I have text value, based on it I need to retrieve its respective lookup id and set the same value to attribute and update the entity

Pleas help me on this

*This post is locked for comments

I have the same question (0)
  • Hosk Profile Picture
    on at

    is this in a plugin or Javasacript

    what version of CRM?

  • DATTA GUNTURU Profile Picture
    590 on at

    Hi,

    I need in C#.

    With Regards,

    Datta.G

  • Suggested answer
    Hosk Profile Picture
    on at

    This blog post has the code to help you

    community.dynamics.com/.../get-optionset-text-from-value-or-value-from-text.aspx

  • DATTA GUNTURU Profile Picture
    590 on at

    Hi Ben Hosking,

    Thank You,

    I need to set GUID for lookup , Isn't ?So, I want to get Guid for Lookup based on the text

    Option text and value will be for Optionlist

    With Regards,

    Datta

  • Suggested answer
    Hosk Profile Picture
    on at

    ahh right

    you need to do a link query or query expression to search the for the record

    query expression

    www.magnetismsolutions.co.nz/.../dynamics_crm_2011_querying_data_with_queryexpression

    linq

    blog.avtex.com/.../using-linq-in-crm-2011-plugins

  • Suggested answer
    Aileen Gusni Profile Picture
    44,524 on at

    Datta,

    You mean lookup Id from text?

    You need to use QueryExpression, Query by Attribute, or fetchxml or Linq to retrieve this and find it using a 'where clause'

    Use the text as keyword to find the lookup id.

    If you use Query by Attribute:

    msdn.microsoft.com/.../gg334708.aspx

    Query Expression + Condition Expression or Filter Expression

    msdn.microsoft.com/.../gg334419.aspx

    msdn.microsoft.com/.../gg309410.aspx

    It will return you Entity Collection (because it is possible to get more than 1 record by a text as keyword) you have to parse it to get only one lookupid.

    If you use Linq:

    msdn.microsoft.com/.../gg328028.aspx

    It is an example from my code:

    *It is to get the city record by name (probably same as your req)

    public tfp_city GetCityInformationByName(BaseContext baseContext, string strName)

           {

               var cityInformation = from x in baseContext.tfp_citySet

                                     where x.tfp_name == strName

                                     select new tfp_city()

                                       {

                                            tfp_name = x.tfp_name,

                                            tfp_CityCode = x.tfp_CityCode,

                                            tfp_cityId = x.tfp_cityId,

                                       };

               if (cityInformation.ToList().Count > 0)

               {

                   return cityInformation.FirstOrDefault();

               }

               else

               {

                   return null;

               }

    Then you will return an entity record which you can get the id:

    targetCity = accountBL.GetCityInformationByName(baseContext, TargetEntity.City);

    Assign to your targent entity:

    TargetEntity.tfp_CityId = targetCity.tfp_cityId.Value;

    or if you use late bound:

    TargetEntity["tfp_cityid"] = targetCity["tfp_cityid"];

    If you need to assign to a lookup then you need an EntityReference 

    TargetEntity["tfp_cityid"] = new EntityReference("tfp_city", guidCityId);

    Which guidCityId id you can get from the previous function.

    You need to generate the Classes and baseContext using crmsvcutil from SDK.

    What is your requirement, lookup field or option set.

    Hope this helps!

    Thanks.

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