Close Activities in CRM 2011

Posted: November 10, 2012 in Code Snippets, CRM 2011
SetStateRequest setStateRequest = new SetStateRequest();

// In my case i'm Cancelling Task Activity
setStateRequest.EntityMoniker = new EntityReference(Task.EntityLogicalName, taskId);
// Set the State and Status OptionSet Values to Cancelled.
setStateRequest.State = new OptionSetValue(2);
setStateRequest.Status = new OptionSetValue(6);
// Execute the Response
SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setStateRequest);

In the same way you can “Cancel” or “Complete” any CRM 2011 Activity by passing the EntityReference accordingly.

Below are the State and Status Code OptionSet values for CRM 2011 Activities.

Phone Call
Service Activity
Campaign Response
Recurring Appointment

  1. Bishnu says:

    Hi Laxman, your blog is always very useful. I have taken help from your website many times. Currently I am looking for how to close task activity. As you mentioned above that code is run in C# plugin or javascript.? my requirement is I want to close task (old one) once I create new task from workflow (on change of field from contact entity). Again field value will change from another system. Not sure how we can accomplish this task. Would you mind to give me some idea?



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 )

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