Update Entity Record Using Dynamic Entity


I want to share somecode to update entity using dynamic entity with all

//Create ICrmService object

ICrmService  _iCrmserviceObject=context.CreateCrmService(true);

//Create Dynamic entity object

 DynamicEntity _DynamicEntity = new DynamicEntity();

//Assign name of entity which you want to update let’s say account

            _DynamicEntity.Name = “account”;

//We have to add properties to dyanic entity that we want to update

//we can add directly to dynamic entity or can first create property and then add that property to dynamic entity

            // Create a KeyProperty to hold the guid of the record to be updated

            _DynamicEntity.Properties.Add(new KeyProperty(“accountid”, new Key(GUID of record which you want to update)));

            _DynamicEntity.Properties.Add(new PicklistProperty(“accountcategorycode”, new Picklist(IntValue)));

            // Create the update target.

            TargetUpdateDynamic _UpdateDynamic = new TargetUpdateDynamic();

            // Set the properties of the target.

            _UpdateDynamic.Entity = _DynamicEntity;

            //   Create the update request object.

            UpdateRequest _UpdateReq = new UpdateRequest();

            //Set request properties.

            _UpdateReq.Target = _UpdateDynamic;

            //Execute the request.

            UpdateResponse updated = (UpdateResponse)_iCrmserviceObject.Execute(_UpdateReq);

Advertisements

Leave a comment

Filed under Dynamic Entity

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s