locked
Howto use GetRelatedEntity in a CRM Plugin RRS feed

  • Question

  • Hello,

    I write currently a CRM 2011 plugin and in the Microsoft.Xrm.Client.dll there is the extension GetRelatedEntity().

    Microsoft.Xrm.Client.dll i can not use in plugins, because the dll is not available on the crm server. Is there another way to get easily the related entities?

    The other way i found is to read the related entities by a self written query, but this is a common task right also should be there a method provided by microsoft.

    Anybody a idea ?

    ---------------------- query i am using ---------------------------

                QueryExpression query = new QueryExpression();
                query.EntityName = "invoice";
                query.ColumnSet = new ColumnSet(true);
                Relationship relationship = new Relationship();
                query.Criteria = new FilterExpression();
                query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, "Active"));
                relationship.SchemaName = "prg_invoice_prg_abrechnungsposition";
                RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection();
                relatedEntity.Add(relationship, query);
                RetrieveRequest request = new RetrieveRequest();
                request.RelatedEntitiesQuery = relatedEntity;
                request.ColumnSet = new ColumnSet(new string[] { "prg_abrechnungspositionid" });
                request.Target = new EntityReference { Id = dienstleistungposition.prg_abrechnungspositionId.Value, LogicalName = "prg_abrechnungsposition" };
                RetrieveResponse response = (RetrieveResponse)localContext.OrganizationService.Execute(request);

    -----------------------------------------------------------------------------------------------------------

    Wednesday, December 4, 2013 3:28 PM

Answers

  • Hello Markus,

    I'm afraid that you will have to use code you've provided.


    Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
    My blog

    • Marked as answer by Markus Benz Thursday, December 5, 2013 7:21 AM
    Wednesday, December 4, 2013 6:58 PM
    Moderator