CRM Blog

Example of Dynamic Entity Update

by Danny Varghese 03.05.09

I have seen numerous requests on other blogs about sample code to on how to update entities in CRM.  One way is to use the CRM web service to update 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 update any record, you must have the proper permissions on that entity.

 

Below is a code example of how to update a record:

 

public void UpdateEntity(ICrmService service)

{

//variable initialization

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

            TargetUpdateDynamic targetUpdate = new TargetUpdateDynamic();      //used to update entity

            UpdateRequest updateRequest = new UpdateRequest();                            //request to update entity

 

entity.Name = <entity name>

 

//add the properties you want to update on the entity

entity.Properties.Add(<property1>);

entity.Properties.Add(<property2>);

entity.Properties.Add(<property3>);

             

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

targetUpdate.Entity = entity;

updateRequest.Target = targetUpdate;

 

//execute the update request

service.Execute(updateRequest);

}

Filed under:

Comments

No Comments

Leave a Comment

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

(required)