我一直在尝试以编程方式停止工作流程。我在各种帖子和 msdn 中都阅读过,这可以通过更新请求更新异步操作状态来完成。但是每次我更新请求。工作流卡在中间阶段,例如取消或暂停,并且没有达到最终状态。
有任何想法吗?
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);
}
}