如何以编程方式设置 Nintex Flexi 任务的任务结果(任务响应)?

发布于 2024-12-22 01:48:27 字数 542 浏览 3 评论 0原文

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

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

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


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

Is there any way of set a Nintex Flexi task completion through Sharepoint's web services? We have tried updating the "WorkflowOutcome", "ApproverComments" and "Status" fields without success (actually the comments and status are successfully updated, however I can find no way of updating the WorkflowOutcome system field).

I can't use the Nintex Web service (ProcessTaskResponse) because it needs the task's assigned user's credentials (login, password, domain).

The Asp.net page doesn't have that information, it has only the Sharepoint Administrator credentials.
One way is to delegate the task to the admin first, and then call ProcessTaskResponse, but it isn't efficient and is prone to errors.


In my tests so far, any update (UpdateListItems) to the WorkflowOutcome field automatically set the Status field to "Completed" and the PercentComplete field to "1" (100%), ending the task (and continuing the flow), but with the wrong answer: always "Reject", no matter what I try to set it to.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月打碎记忆 2024-12-29 01:48:27

您是否尝试过此代码:(带有重定向的 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
{
}

Did you try this code: (try-cacth block with redirection does the trick)

\\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
{
}

?

黎歌 2024-12-29 01:48:27

这是我更改 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;
        }

Here are my code to change outcome of nintex flexi task. My problem is permission. I had passed admin token to site. It's solve the problem.

           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;
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文