CRM Blog

Example of Dynamic Entity Create

by Danny Varghese 03.04.09

There have been numerous requests on other blogs about sample code to on how to create entities in CRM.  One way is to use the CRM web service to create business entities, however by doing so, you're only limited to out-of-the-box entities with system attributes.  To retrieve anything more "dynamic," you'll have to employ other methods.  Please remember that in order to create any record, you must have the proper permissions on that entity.

 

Below is a code example of how to create a record using dynamic entities:

 

public void CreateEntity(ICrmService service)

{

//variable initialization

DynamicEntity entity = new DynamicEntity();                                                 //target entity to update

TargetCreateDynamic targetCreate = new TargetCreateDynamic();          //used to update entity

CreateRequest createRequest = new CreateRequest();                                //request to create entity

 

entity.Name = <entity name>

 

//add the properties                   

entity.Properties.Add(<property>);

Entity.Properties.Add(<property>);

 

//set the target to update, and the request to update for

targetCreate.Entity = entity;

createRequest.Target = targetCreate;

 

//execute the update request

service.Execute(createRequest);

}

 

Hope this helps, happy coding!

Filed under:

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Security Check
Please answer the simple math problem below.

(required)