zoukankan      html  css  js  c++  java
  • How to unlock the locked tasks in Sharepoint Workflow

    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 :)
  • 相关阅读:
    设计模式(Design Pattern)扫盲
    SharePoint 2007 采用表单验证 (1) 失败:(
    发布一款给图片批量加水印的程序PicNet V1.0
    转篇文章,VS2005开发的dll如何安装进GAC
    cnblogs排名进入1500,纪念一下
    转载一篇提高baidu/google收录的文章
    关于.NET(C#)中字符型(Char)与数字类型的转换, CLR via c# 读书笔记
    《天风文章》V1.2.0 新闻/文章类asp.net2.0站点系统源码 (100%开源)
    推荐个.Net的论坛系统 Discuz!NT
    C#实现对图片加水印的一段代码.
  • 原文地址:https://www.cnblogs.com/ahghy/p/2731303.html
Copyright © 2011-2022 走看看