Manipulating Workflows Server Side

Discussion created by hughpa9 on May 17, 2017



I'm looking at writing a custom SharePoint farm solution that is backed by a Nintex workflow. Part of this solution involves interacting with the workflow server side via a SharePoint hosted WCF service. The goal is to have an endpoint that updates data in a database and starts a workflow.


I'm looking at using the SDK libraries available in the Nintex.Workflow assembly and am just curious if anybody has used these previously and if there are any best practices or gotchas when working with these classes. In particular, I'm looking at the functionality involved with retrieving, actioning & delegating flexi and to do tasks.


I have had success using the following methods within the SDK:

  • UserTaskCollection.GetPendingWorkflowTasks(),
  • NintexTask.RetrieveTask()
  • NintexTask.RetrieveSPListItem()
  • ConfiguredOutcome.GetOutcomeId() 

As well as using the  the SPBuiltInFieldId.TaskStatus, NWSharePointObjects.FieldDecision and NWSharePointObjects.FieldComments fields as appropriate to update the associated task list item (see below for code sample). Is there anything else I should be doing (e.g. task locking) or is this approach going to be reliable?


// Action a task

// Obtain task details

var taskList = web.GetList(listUrl);

var nintexTask = NintexTask.RetrieveTask(taskId, web, taskList);
listItem = NintexTask.RetrieveSPListItem(taskId, web, taskList);
approver = nintexTask.Approvers.GetBySPId(taskId);


// Check if current user is assignee...


// For todo tasks

// Using OOTB SP here as per Processing workflow task responses 

var updateFields = new Hashtable(1);
updateFields[SPBuiltInFieldId.TaskStatus] = "Complete";
SPWorkflowTask.AlterTask(listItem, updateFields, true);


// For flexi tasks

var outcomeId = ConfiguredOutcome.GetOutcomeId(flexiData.Outcome, web);
var comments = "";

listItem[NWSharePointObjects.FieldDecision] = outcomeId;
listItem[NWSharePointObjects.FieldComments] = comments;


I have looked at the workflow service and while this has all the functionality required, I have yet to be able to find a way of using a service reference to execute the appropriate methods under the context of the current user. In particular, actioning tasks always result in an InvalidUser response (I'm assuming it is trying to use the app pool account). If there is a way around this, I'd be more than happy to go along with the web service route.