How do I programmatically access a PARENT ENTITY starting from one of its CHILDREN (using Microsoft.Xrm.Sdk) ? RRS feed

  • Question

  • Hi all,

    I'm building a custom solution to integrate CRM 2011 with SharePoint 2010.

    Without going too much into details, I am writing a plugin to be fired on the post creation of a "document location" entity (the entity containing information about the SharePoint location). This plugin needs to access the parent entity (a Contact in my case) to which the "document location" belongs and read its ID in order to write it into SharePoint.

    A SharePoint item Event Receiver will then be fired when documents are uploaded/modified and, using the entity ID previously written into its parent folder metadata, will access CRM via WCF app to retrieve the entity metadata and do some work with it.

    My question is: I can easily create queries to retrieve related entities (children) starting from a specific entity, but can I go the other way (retrieving a parent entity from one of its children?)

    Hope I've been clear enough



    Wednesday, July 3, 2013 1:52 AM

All replies

  • The parent would, generally speaking, be referenced in a Lookup field.  Once you have the schema name of this field, the rest is easy.  You can query for it manually, or you can pass it into your Plugin using Entity Images, which are a component of Plugin Step registration.  I generally use Entity Images, but if I'm hooked into the Create or Update messages, I check the "Target" InputParameter for better data (since its presence in both messages represents an initialization or change, respectively).

    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.

    Wednesday, July 3, 2013 2:20 AM