How to unlock the locked tasks in Sharepoint Workflow

解锁SharePoint工作流任务
本文提供了一种解决SharePoint工作流中任务被锁定的问题的方法。通过更新任务的WorkflowVersion字段为1,可以解除锁定状态,使任务可以继续进行。

How to unlock the locked tasks in Sharepoint Workflow

 
Sometimes in Sharepoint Workflow, tasks will get locked and you will not be able to proceed further.

These locks are placed to prevent the task being updated simultaneously. The workflow runtime locks tasks by setting a field (WorkflowVersion)and persisting that to the database.

if workflowversion is 1 then the tasks are "not locked". Any value apart from "1" symbolises that these tasks are "locked".

Ideally to remove the locks, we need to update WorkflowVersion of the task to "1".

Here you go, the sample for it.


public static void UnlockWorkflowTasks(string siteUrl, string webUrl, string listName)
        {
            using (SPSite site = new SPSite(siteUrl))
            {
                using (SPWeb web = site.OpenWeb(webUrl))
                {
                    SPList list = web.Lists[listName];
                    SPListItemCollection items = list.Items;
 
                    foreach (SPListItem item in items)
                    {
                        SPWorkflowCollection workflows = item.Workflows;
                        foreach (SPWorkflow workflow in workflows)
                        {
                            SPWorkflowTaskCollection tasks = workflow.Tasks;
                            foreach (SPWorkflowTask task in tasks)
                            {
                                if (task[SPBuiltInFieldId.WorkflowVersion].ToString() != "1")
                                {
                                    task[SPBuiltInFieldId.WorkflowVersion] = 1;
                                    task.SystemUpdate();
                                }
                            }
                        }
                    }
                }
            }
        }
 

Happy Coding :)

转载于:https://www.cnblogs.com/ahghy/archive/2012/10/19/2731303.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值