我经常收到重新启动某些列表项工作流的请求。我编写了一个应用程序,它将库名和列表项名称作为输入。当我尝试启动工作流程(StartWorkflow方法)时,我从HRESULT得到此错误异常:0x8102009B并且没有内部异常。以下是我的代码。
有时工作流程可能已经启动。在这种情况下,我需要取消工作流程,然后重新启动。
我在这个问题上做了很多搜索。大多数决议适用于SP 2010.我们正在使用SP Online
clientContext.Credentials = new SharePointOnlineCredentials(Userid, Password);
var web = clientContext.Web;
List list = web.Lists.GetByTitle("listname");
clientContext.Load(list);
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><Query><OrderBy><FieldRef Name='FileLeafRef' Descending='True'/></OrderBy><Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>" + ListItemName + ".xml</Value></Eq></Where></Query><RowLimit>1</RowLimit></View>";
ListItemCollection items = list.GetItems(camlQuery);
clientContext.Load(items);
clientContext.ExecuteQuery();
var id = items.Where(a => a.FieldValues["FileLeafRef"].ToString() == ListItemName + ".xml").Select(a => a.Id).FirstOrDefault();
Guid listItemID = (Guid)items.Where(a => a.FieldValues["FileLeafRef"].ToString() == ListItemName + ".xml").Select(a => a.FieldValues["GUID"]).FirstOrDefault();
WorkflowAssociationCollection wfaCollection = items.Where(a => a.FieldValues["FileLeafRef"].ToString() == ListItemName + ".xml")
.Select(a => a.ParentList.WorkflowAssociations).FirstOrDefault();
clientContext.Load(wfaCollection);
var workflowServiceManager = new WorkflowServicesManager(clientContext, web);
clientContext.Load(workflowServiceManager);
clientContext.ExecuteQuery();
InteropService workflowInteropService = workflowServiceManager.GetWorkflowInteropService();
clientContext.Load(workflowInteropService);
var wfaName = wfaCollection.Where(a => a.Enabled == true).Select(a => a.Name).FirstOrDefault();
Guid wfaId = wfaCollection.Where(a => a.Enabled == true).Select(a => a.Id).FirstOrDefault();
var initiationData = new Dictionary<string, object>();
ClientResult<Guid> resultGuid = workflowInteropService.StartWorkflow(wfaName, new Guid(), list.Id, listItemID, initiationData);
clientContext.ExecuteQuery();