Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieving Guid of a lookup field

(0) ShareShare
ReportReport
Posted on by 60

I am looking for a c# code to get the GUID of a lookup field.  This should be a generic code to accommodate any entity. 

Following is the scenario.

Need to create a lead  from a external web form. In web form  Nationality is provided as Text.   This text needs to be translated to   GUID  to add lookup field in the lead form.  

What I need a function which  receive parameter Lookup table, lookupGUIDcolumnName, and LookupTextColumnName.

eg: Lookup table = crm_nationality

     lookupGUIDcolumnName= crm_nationalityId

     LookupTextColumnName = crm_nationalityText

Any help is greatly appreciated. 

                   

*This post is locked for comments

  • jma728 Profile Picture
    60 on at
    RE: Retrieving Guid of a lookup field

    Hi David,

    The code you provided is worked well for me.  Thanks a lot.

  • Verified answer
    David Jennaway Profile Picture
    14,065 on at
    RE: Retrieving Guid of a lookup field

    You can do this using QueryByAttribute to get the GUID of a record based on matching on a field value. It would look something like this:

    You'll then need to check how many records are returned - ideally it would be one, but you should handle the scenarios of 0 records (no match), or multiple records (duplicates). If duplicates are possible, you can use the Orders property to specify the order

    QueryByAttribute qa = new QueryByAttribute(LookupTable);
    qa.ColumnSet = new ColumnSet(LookupTextColumnName, LookupGUIDcolumnName);
    //  Attribute to query.
    qa.Attributes.AddRange(LookupTextColumnName);
    //  Value of queried attribute to return.
    qa.Values.AddRange(LookupTextValue);
    EntityCollection ec = _service.RetrieveMultiple(qa);


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 CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans