如何使用代码单击按钮终止SharePoint Designer 2013工作流. [英] How to Terminate SharePoint Designer 2013 Workflow using code on-click button .

查看:83
本文介绍了如何使用代码单击按钮终止SharePoint Designer 2013工作流.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用代码单击按钮终止SharePoint Designer 2013工作流.

How to Terminate SharePoint Designer 2013 Workflow using code on-click button .

我想通过单击表单上的按钮来终止工作流程.

I want to terminate my Workflow by clicking a button on my form. 

Shiv Sharma

Shiv Sharma

推荐答案

你好,

请尝试以下代码,它是服务器端C#

Please try the following code, it is server side C#

using (var site = new SPSite(siteUrl))
{
	using (var web = site.OpenWeb())
	{
		var list = web.GetListFromUrl("Lists/ListName/AllItems.aspx");

		var item = list.GetItemById(yourItemId);
		
		var workflowServiceManager = new WorkflowServicesManager(web);

		var workflowInstanceService = workflowServiceManager.GetWorkflowInstanceService();
	
		try
		{
			var itemActiveWorkfows = workflowInstanceService.EnumerateInstancesForListItem(list.ID, item.ID);
			
			foreach (WorkflowInstance itemWorkflow in itemActiveWorkfows)
			{
				if (itemWorkflow.Status.Equals(WorkflowStatus.Started))
				{
					workflowInstanceService.CancelWorkflow(itemWorkflow);
				}
			}
		}
		catch (Exception ex)
		{
			Console.WriteLine(


异常消息{ex.Message}")); Console.WriteLine(
"Exception Message {ex.Message}"); Console.WriteLine(


异常内部异常{ex.InnerException}"); Console.WriteLine(
"Exception Inner Excerption {ex.InnerException}"); Console.WriteLine(


这篇关于如何使用代码单击按钮终止SharePoint Designer 2013工作流.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆