Set Status(Activate/De-activate) of the CRM record


We do activate and deactivate CRM record more often. Sometimes, we get the requirement to do the same in the plugin/workflow/some job.

Here is the code for activating and de-activating the CRM record.

private void SetStatus(bool active, string entityName, Guid entityId, IOrganizationService objService)

       SetStateRequest objSetStateRequest = new SetStateRequest();
       objSetStateRequest.EntityMoniker = new EntityReference(entityName, entityId);
       if (!active)
             objSetStateRequest.State = new OptionSetValue(1);
             objSetStateRequest.Status = new OptionSetValue(2);
             objSetStateRequest.State = new OptionSetValue(0);
             objSetStateRequest.Status = new OptionSetValue(1);
       SetStateResponse objSetStateResponse = (SetStateResponse)objService.Execute(objSetStateRequest);

Hope this helps

Happy CRM’ing

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s