3

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.

tiago2014
  • 3,392
  • 1
  • 21
  • 28

2 Answers2

1

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

?

gdbdable
  • 4,445
  • 3
  • 30
  • 46
  • This code does not approve it. It doesn't work for Flexi tasks unfortunately (I tried it). It does show itself as "Completed" but actually the task is pending. I would love to know the answer to this. – Jakub Holovsky Mar 17 '14 at 20:15
  • @JakubHolovsky, please try my updated answer, redirect with try-catch very important here! – gdbdable Mar 20 '14 at 10:14
  • Hey, what Dll do you have to reference to use Nintex.Workflow.Utility.RedirectOrCloseDialog(HttpContext.Current, Web.Url); ? Thank you – Jakub Holovsky Apr 16 '14 at 01:45
  • 1
    @JakubHolovsky, you need reference Nintex.Workflow.dll and Nintex.Workflow.ServerControls.dll – gdbdable Apr 16 '14 at 15:18
1

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;
        }