web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

MS CRM 2011: How to cancel Workfow Instance using C#

a33ik Profile Picture a33ik 84,331 Most Valuable Professional
Today I had a task to cancel about 25k instances of the same workflow. Of course it was possible to create Advanced Find View and go through 100 pages cancelling all workflows on the page. But I’m too lazy and I know C# to do that manually.
First code that I wrote used SetState message to Cancel change state of workflow instance but during first lunch I’ve got an exception that SetState message is not applicable for AsyncOperation entity. I went to SDK and found following explanation:
Updates an asynchronous operation (system job). Typically, you would update only the AsyncOperation.StateCode or AsyncOperation.PostponeUntil attributes of the asynchronous operation (system job). You can also call the IOrganizationService.Update method.
So I rewrote my code using Update message:
Entity operation = new Entity("asyncoperation")
{
Id = <Put identifier of Workflow Instance here>
};

operation["statecode"] = new OptionSetValue(3);
operation["statuscode"] = new OptionSetValue(32);

organizationservice.Update(operation);


This was originally posted here.

Comments

*This post is locked for comments