Create Related Entity Records in Dynamics CRM using SDK

By | March 24, 2010

In Dynamics CRM, if you were to create a related entity from within the Parent entity, take for example you create a new contact from within the Account form, the account address and other related information is automatically copied over to the new Contact as well.

If CRM does this, there sure must be a way to get this done programmatically as well, and yes there is a message that helps you do just this.

The message is InitializeFromRequest. You need to need to provide the following details to this request to have it create the related entity with all the related information from the Parent entity copied over.

EntityMoniker = The moniker data type of the source/parent entity from which details need to be copied over.
TargetEntityName = The type of entity that you want to create from the given parent entity

Once this message is executed it will return the requested entity object. Note that at this stage only the details have been copied over but this record has not yet been created in CRM. You can process this instance further to set other properties if required and then use the Service.Create message to create the entity instance in CRM.

You can check out the SDK (hyperlink sdk to the following url http://msdn.microsoft.com/en-us/library/bb956722.aspx) for further details on this message.

Leave a Reply

Your email address will not be published. Required fields are marked *