i've been trying to stop a workflow programmatically. I've read both in various posts and in the msdn that this can be done by updating the Asyncoperation status via update request. However everytime i update the request. the workflow get stuck on a mid stage such as cancelling or pausing and dosen't reach a final state.
any ideas?
protected void ExecutePostAccountUpdate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
string fetchXML = "<fetch mapping='logical' count='50' version='1.0'>" +
"<entity name='asyncoperation'>" +
"<filter>" +
"<condition attribute='regardingobjectid' operator='eq' value='" +
localContext.PluginExecutionContext.PrimaryEntityId + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";
EntityCollection col = localContext.OrganizationService.RetrieveMultiple(new FetchExpression(fetchXML));
if (col.Entities.Count > 0)
{
AsyncOperation a = (AsyncOperation)col[0];
a.StateCode = AsyncOperationState.Completed;
a.StatusCode = new OptionSetValue(32);
localContext.OrganizationService.Update(a);
}
}
StateCode
andStatusCode
don't usually respond too well to generic updates. Have you tried issuing aSetStateRequest
instead? – Peter Majeed