SharePoint 模拟审批Nintex工作流

Posted 霖雨

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SharePoint 模拟审批Nintex工作流相关的知识,希望对你有一定的参考价值。

  前言

  这个也是多年以前保存的草稿了,当时在XX公司做Nintex工作流的项目写的代码。

  简单的介绍下场景,因为跨过公司,很多人有多个域的同名账号(A\\linyu B\\linyu C\\linyu),但是审批的时候工作流可不认这个啊,你给哪个账号权限哪个才能批,才能看见Task。后来写了个Service,发Ajax请求进行审批,通过服务器对象模型模拟权限审批。前台task也通过用户名来过滤,不要域的名字,完美解决了用户多域审批的问题。

using (SPSite site = new SPSite(SiteUrl, sysToken))

    using (SPWeb web = site.OpenWeb())
    
        SPList list = web.Lists.TryGetList(ListName);
        SPListItem item = list.GetItemById(ItemId);
        SPWorkflow workflow = item.Workflows[0];
        SPWorkflowTask task = workflow.Tasks[0];
        task.Web.AllowUnsafeUpdates = true;
        Hashtable ht = new Hashtable();
        ht[SPBuiltInFieldId.TaskStatus] = SPResource.GetString(new CultureInfo((int)task.Web.Language, false), Strings.WorkflowStatusCompleted, new object[0]);
        ht["Completed"] = true;
        ht["PercentComplete"] = 1;
        ht["Status"] = "Completed";
        ht["WorkflowOutcome"] = OutCome;
        ht[Nintex.Workflow.Common.NWSharePointObjects.FieldDecision] = GetFlexiTaskOutcomeId(task, OutCome);
        ht[Nintex.Workflow.Common.NWSharePointObjects.FieldApprovalOutcome] = GetFlexiTaskOutcomeId(task, OutCome);
        ht["ApproverComments"] = Comment;
        ht["FormData"] = SPWorkflowStatus.Completed;
        result = AlterTask((task as SPListItem), ht, true, 5, 100);
        task.Web.AllowUnsafeUpdates = false;
    

   好多年前写的代码了,大家凑合看吧。 

public static bool AlterTask(SPListItem task, Hashtable htData, bool fSynchronous, int attempts, int milisecondsTimeout)

    if ((int)task[SPBuiltInFieldId.WorkflowVersion] != 1)
    
        SPList parentList = task.ParentList.ParentWeb.Lists[new Guid(task[SPBuiltInFieldId.WorkflowListId].ToString())];
        SPListItem parentItem = parentList.Items.GetItemById((int)task[SPBuiltInFieldId.WorkflowItemId]);
        for (int i = 0; i < attempts; i++)
        
            SPWorkflow workflow = parentItem.Workflows[new Guid(task[SPBuiltInFieldId.WorkflowInstanceID].ToString())];
            if (!workflow.IsLocked)
            
                task[SPBuiltInFieldId.WorkflowVersion] = 1;
                task.SystemUpdate();
                break;
            

            if (i != attempts - 1)
            
                Thread.Sleep(milisecondsTimeout);
            
        
    

    var result = SPWorkflowTask.AlterTask(task, htData, fSynchronous);
    return result;


public static string GetFlexiTaskOutcomeId(Microsoft.SharePoint.Workflow.SPWorkflowTask task, string outcome)

    if (task["MultiOutcomeTaskInfo"] == null)
    
        return string.Empty;
    
    string xmlOutcome = HttpUtility.htmlDecode(task["MultiOutcomeTaskInfo"].ToString());
    if (string.IsNullOrEmpty(xmlOutcome))
    
        return string.Empty;
    
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xmlOutcome);
    var node = doc.SelectSingleNode(string.Format("/MultiOutcomeResponseInfo/AvailableOutcomes/ConfiguredOutcome[@Name='0']", outcome));
    return node.Attributes["Id"].Value;

以上是关于SharePoint 模拟审批Nintex工作流的主要内容,如果未能解决你的问题,请参考以下文章

SharePoint 模拟审批Nintex工作流

SharePoint 模拟审批Nintex工作流

SharePoint 模拟审批Nintex工作流

SharePoint Online 触发Teams审批

SharePoint Online 触发Teams审批

SharePoint Online 触发Teams审批