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

时间:2011-12-20 20:28:13

标签: sharepoint-2010 nintex-workflow

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

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

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


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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分: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;
        }