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)

Link To Multiple Entities

(0) ShareShare
ReportReport
Posted on by

I have written the code to fetch fields of vice entity.

Entity1 - vice

Entity2 - ment

Entity3 - Model

Now Entity 2 has a lookup Model which is an entity. I need Model "name".  

Can any 1 please help how to retrieve related entity Entity 3 (Model) from Entity 2(ment)

QueryExpression qureyObj = new QueryExpression("vice");
qureyObj.NoLock = true;
qureyObj.Distinct = true;
qureyObj.ColumnSet = new ColumnSet(true);
qureyObj.Criteria.AddCondition(new ConditionExpression("companyid", ConditionOperator.Equal, "{441P363D-0DB4-E711-80E2-001DD8B721AB}"));

LinkEntity viceEquipment = new LinkEntity(" vice", "ment", " mentid", " mentid", JoinOperator.LeftOuter);
viceEquipment.EntityAlias = "DE";
viceEquipment.Columns = new ColumnSet(true);
qureyObj.LinkEntities.Add(deviceEquipment);

*This post is locked for comments

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

    Hi Meetchu,

    The Model will be a EntityReference on ment entity.

    The following code would help you to retrieve the name of the Model record name referred in Ment record. Once you execute the query above you would be able to identify the entity reference attribute using Aliasing

    var result = Service.RetrieveMultiple(queryObj).Entities.FirstorDefault();

    var modelRef = result.GetAttributeValue<AliasedValue>(DE.(schema name of model attribute));

    string modelName = string.Empty;

    if(modelRef != null)

    {

          if(modelRef.Name != null )

                  modelName = modelRef.Name;

          else

    {

                  var modelResult = Service.Retrieve(modelRef.LogicalName, modelRef.Id , new ColumnSet("name"));

                 if(modelResult != null)

                {

                  modelName = modelResult.Attributes["name"].ToString();

                }

    }    

    }

    Hope this helped.

    Thanks

    Phanidhar

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    This is an example with user roles, you can modify it as you see needed:

               QueryExpression query = new QueryExpression()

               {

                   EntityName = "role",

                   ColumnSet = new ColumnSet("roleid"),

                   LinkEntities =

                   {

                       new LinkEntity()

                       {

                           LinkFromEntityName = "role",

                           LinkFromAttributeName = "roleid",

                           LinkToEntityName = "systemuserroles",

                           LinkToAttributeName = "roleid",

                           LinkEntities = {

                               new LinkEntity()

                                           {

                                               LinkFromEntityName = "systermuserroles",

                                               LinkFromAttributeName = "systemuserid",

                                               LinkToEntityName = "systemuser",

                                               LinkToAttributeName = "systemuserid",

                                               LinkCriteria =

                                               {

                                                   Conditions =

                                                   {

                                                       new ConditionExpression("systemuserid", ConditionOperator.Equal, userId)

                                                   }

                                               }

                           }

                       }

                   },

                   Criteria =

                   {

                       Conditions =

                       {

                           new ConditionExpression("roleid", ConditionOperator.Equal, roleId)

                       }

                   }

               };

    You can check out the following link for an additional sample:

    www.briteglobal.com/.../retrieve-all-records-owned-by-other-team-members-2

    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

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