3

有没有办法通过 Sharepoint 的网络服务设置 Nintex Flexi 任务完成?我们已经尝试更新“WorkflowOutcome”、“ApproverComments”和“Status”字段但没有成功(实际上评论和状态已成功更新,但我找不到更新 WorkflowOutcome 系统字段的方法)。

我无法使用 Nintex Web 服务 (ProcessTaskResponse),因为它需要为任务分配的用户凭据(登录名、密码、域)。

Asp.net 页面没有该信息,它只有 Sharepoint 管理员凭据。一种方法是先将任务委托给管理员,然后调用ProcessTaskResponse,但效率不高,容易出错。


到目前为止,在我的测试中,对 WorkflowOutcome 字段的任何更新 (UpdateListItems) 都会自动将 Status 字段设置为“Completed”,将 PercentComplete 字段设置为“1”(100%),从而结束任务(并继续流程),但错误答案:无论我尝试将其设置为什么,始终“拒绝”。

4

2 回答 2

1

您是否尝试过此代码:(带有重定向的 try-cacth 块可以解决问题)

\\set to actual outcome id here, for ex. from OutComePanel control
taskItem[Nintex.Workflow.Common.NWSharePointObjects.FieldDecision] = 0; 

taskItem[Nintex.Workflow.Common.NWSharePointObjects.FieldComments] = " Some Comments";
taskItem.Update();
try
{
   Nintex.Workflow.Utility.RedirectOrCloseDialog(HttpContext.Current, Web.Url);
}
catch
{
}

?

于 2013-01-28T13:38:52.567 回答
1

这是我更改 nintex flexi 任务结果的代码。我的问题是权限。我已将管理员令牌传递给站点。它解决了问题。

           var siteUrl = "...";
            using (var tempSite = new SPSite(siteUrl))
            {
                var sysToken = tempSite.SystemAccount.UserToken;
                using (var site = new SPSite(siteUrl, sysToken))
                {
                    var web = site.OpenWeb();
                    ...

                                    var cancelled = "Cancelled";
                                    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"] = cancelled;
                                    ht["Decision"] = CommonHelper.GetFlexiTaskOutcomeId(task, cancelled);
                                    ht["ApproverComments"] = "cancelled";
                                    CommonHelper.AlterTask((task as SPListItem), ht, true, 5, 100);

                                    task.Web.AllowUnsafeUpdates = false;
                                }
                            }
                        }
                    }
                }
            }



  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;
            }
 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;
        }
于 2017-03-06T08:07:50.940 回答