我正在尝试以编程方式启动SharePoint 2013工作流程。工作流程采用五个参数,将它们放入电子邮件正文中并通过电子邮件发送给我。当我访问SharePoint网站时,我可以手动启动此工作流程,因此我知道工作流程是正确的。当我尝试使用SharePoint API来启动工作流程时,我没有收到任何错误,我得到一个空的Guid,并且工作流程没有运行。
public Guid Add(Project project)
{
var result = Guid.Empty;
var siteUri = new Uri(ConfigurationManager.AppSettings["SharePoint.Site"]);
var workflowName = ConfigurationManager.AppSettings["SharePoint.WorkflowName"];
using (var clientContext = TokenHelper.GetS2SClientContextWithWindowsIdentity(siteUri, null))
{
var workflowServiceManager = new WorkflowServicesManager(clientContext, clientContext.Web);
var workflowSubscriptionService = workflowServiceManager.GetWorkflowSubscriptionService();
var subscriptions = workflowSubscriptionService.EnumerateSubscriptions();
clientContext.Load(subscriptions, subs => subs.Where(sub => sub.Name == workflowName));
clientContext.ExecuteQuery();
foreach (var subscription in subscriptions)
{
var instanceService = workflowServiceManager.GetWorkflowInstanceService();
var initiationData = new Dictionary<string, object>
{
{"pProjectName", project.Name},
{"pDivision", _divisionData.GetDivisionName(project.DivisionId ?? Guid.Empty) },
{"pOperatingGroup", "****TODO: Operating Group****"},
{"pClientName", _clientData.GetClientName(project.ClientId ?? Guid.Empty) },
{"pSiteUrl", "****TODO: Site URL****" }
};
var startResult = instanceService.StartWorkflow(subscription, initiationData);
result = startResult.Value;
}
}
return result;
}
答案 0 :(得分:0)
string subscriptionID = "WFListSubscriptionID of your wf";//it is a guid
int itemID = "Item.ID, Id of a item that you start wf for";
Guid workflowSubscriptionIdGuid = new Guid(subscriptionID);
var workflowServiceManager = new WorkflowServicesManager(item.Web);
var workflowSubscriptionService = workflowServiceManager.GetWorkflowSubscriptionService();
var workflowSubscription = workflowSubscriptionService.GetSubscription(workflowSubscriptionIdGuid);
var inputParameters = new Dictionary<string, object>();
workflowServiceManager.GetWorkflowInstanceService().StartWorkflowOnListItem(workflowSubscription, itemID, inputParameters);