Working with Custom Entites in MS CRM 4.0

Working with Custom Entities has been a little tough on me because of the High Learning curve involved.  Finally I did win over and learnt quite a bit about using these entities in custom pages. It’s actually quite simple to work with the custom entities. Here’s a piece of code which will get the custom entity into a dynamic entity for us

//Create of New information the custom entity
DynamicEntity de_Custom = new DynamicEntity();
de_Custom.Name = "CustomEntityName";
de_Custom.Properties = PropertiesCollectionObject;
TargetCreateDynamic tcd_Custom = new TargetCreateDynamic();
tcd_Custom.Entity = de_Custom;  <a href="" class="more-link">Continue reading <span class="meta-nav">&rarr;</span></a>

In the second line of the code, is where the magic happens. Here all you have to do is specify the custom/system entity name , when querying the web service, will automatically bind to the entity. PropertiesCollectionObject is a collection of Properties which has all the data (type & value information) which is to be inserted in the entity. Here is an sample of what we will have in the PropertiesCollectionObject

Microsoft.Crm.Sdk.PropertyCollection pc_Properties = new 
StringProperty sp_Prop = new StringProperty();
sp_Prop.Name = "EntityFieldName";
sp_Prop.Value = "ValueToBeInserted;

This property collection will have all the properties like Boolean,Picklist,
Lookup and Number, depending on your requirement. This will get bound with the
property collection in the entity object. When CRMService executes the request
it takes the data and the fieldnames inside these properties and inserts them

Please do let me know if i have missed something.

Leave a Reply

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