retrieve columns from LinkedEntities in Microsoft CRM 2011

Hi,

You prepare QueryExpression and add some LinkedEntities then you want to retrieve fields from linked part.Just follow the sample;


 QueryExpression query = new QueryExpression()
                    {
                                        ...
                                        ...
                    };

                    FilterExpression filterTicket = new FilterExpression();
                    ...
                    query.Criteria = filterTicket;

                    //all about ticket
                    query.LinkEntities.Add(new LinkEntity("contact", "new_new_ticket_contact", "contactid", "contactid", JoinOperator.Inner));


                    query.LinkEntities[0].EntityAlias = "contacttoticket";
add alias to reach the fields
                    query.LinkEntities[0].Columns.AddColumn("new_ticketid");
add column names to the same level of LinkedEntity to obtain later...


                    query.LinkEntities[0].AddLink("new_ticket", "new_ticketid", "new_ticketid", JoinOperator.Inner);
                    query.LinkEntities[0].LinkEntities[0].EntityAlias = "contacttotickecttonew_customtable";
                    query.LinkEntities[0].LinkEntities[0].Columns.AddColumn("new_tourid");
                    query.LinkEntities[0].LinkEntities[0].AddLink("new_customtable", "new_customtable", "new_customtableid", JoinOperator.Inner);
                    ...

                    ...

You can get Linked Entities field(s) via Attributes from the response object  after execute the query against CRM Service Proxy.
AliasedValue is type of the returning object and has a value parameter which may be EntityReference or Entity, based upon joined object.


 if (ent.Attributes.Contains("contacttotickecttonew_customtable"))
                        {
                          string str =  ((EntityReference) ((AliasedValue) ent.Attributes["contacttotickecttonew_customtable"]).Value).Id
                        }


regards,

Comments

Popular posts from this blog

Complex Query in QueryExpression in Microsoft CRM 2011

Microsoft Power Apps Portal integration with Dynamics 365 CE On-Premise - Step By Step Guide

Exception caught instantiating TERADATA report server extension SQL Reporting Services