Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Querying a guid field for related record

Posted on by Microsoft Employee

Hello,

I have two entities, lets say E1 and E2. In E1, there is a lookup field to the E2. I am storing the Guid of the E2 record selected as lookup in a field in the E1. (Converting Guid to string). Now , in another function I want to retrieve the E2 record by querying the field in which guid is stored in  E1. I am doing the following :

string GuidOfE2record = e1["field in which guid is stored"].ToString();

 var E2record = crmService.Retrieve(schemanameofE2, GuidOfE2record, new ColumnSet("name"));

However, I am facing issues because of string conversion. However , if I remove ToString(), (Tried Guid GuidOfE2record = e1["field in which guid is stored"];)I am facing error that it cannot convert object to guid. How do I solve this issue?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Querying a guid field for related record

    Thank you!

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Querying a guid field for related record

    You can convert to Guid:

    Guid recordE2Id = new Guid(e1["GuidFieldName"].ToString());

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans