Activate/Deactivate Entities – Statuscode and statecode values

To change the state of an Entity via C# we can not use the update command, we need to create a service request as follows.

//Activate  Registry.
Microsoft.Crm.Sdk.Messages.SetStateRequest setContact = new Microsoft.Crm.Sdk.Messages.SetStateRequest();
setContact.EntityMoniker = new EntityReference("contact", ContactGuid);
setContact.State = new OptionSetValue(0);
setContact.Status = new OptionSetValue(-1);
service.Execute(setContact);

//Deactivate  Registry.
Microsoft.Crm.Sdk.Messages.SetStateRequest setContact = new Microsoft.Crm.Sdk.Messages.SetStateRequest();
setContact.EntityMoniker = new EntityReference("contact", ContactGuid);
setContact.State = new OptionSetValue(1);
setContact.Status = new OptionSetValue(2);
service.Execute(setContact);

All the info about the different StateCode and status code values in this Microsoft post.

Advertisements

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