Reputation: 327
I am trying to find a way to cancel a workflow using the Dynamics CRM SDK. Currently I can retry a workflow, but I am having issues being able to cancel one programatically. Is this possible?
Upvotes: 0
Views: 2394
Reputation: 229
To Start a workflow:
ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
{
WorkflowId = Workflow.Id,
EntityId = entity.Id
};
// Execute the workflow.
ExecuteWorkflowResponse response =
(ExecuteWorkflowResponse)service.Execute(request);
To End:
Entity operation = new Entity("asyncoperation")
{
Id = WorkflowRef.Id
};
operation["statecode"] = new OptionSetValue(3);
operation["statuscode"] = new OptionSetValue(32);
organizationservice.Update(operation);
Upvotes: 3
Reputation: 17562
Have you seen Asynchronous Operation States?
Apparently you just need to make an update call of the statecode
.
Retrieving and Updating AsyncOperation States
Monitoring and updating the state of an asynchronous operation is typically done interactively through the System Jobs grid in the Microsoft Dynamics CRM Web application. However, you can also use the SDK to write code that performs those same tasks.
Read the state of an asynchronous operation
Retrieve an AsyncOperation by name using the RetrieveMultiple method or by ID using the Retrieve method.
Read the AsyncOperation.StateCode attribute.
Change the state code
Modify the retrieved state code attribute to a new value according to the allowed operation states. You could also change the AsyncOperation.PostponeUntil attribute.
Call Update to change the value of those attributes in the database.
Upvotes: 1