Processing workflow task responses

You can process task responses for workflow tasks, including Flexi task workflow tasks, by using a few service operations provided by both Nintex Workflow 2013 and SharePoint 2013, depending on the type of workflow task to be processed. For more information about workflow task types, see Workflow tasks.

Processing workflow approval and review tasks

You can use the ProcessTaskResponse3 service operation to process task responses for workflow approval and review tasks. Such workflow tasks use the Outcome enumeration, rather than a user-defined set of configured outcomes, to specify an outcome for a workflow task.

Example

The following example uses the ProcessTaskResponse3 service operation to process a task response for a workflow task.

public bool ProcessTaskResponse(int spTaskId,
    string taskListName,
    Outcome outcome,
    string comments)
{
    bool retVal = false;
    try
    {
        // Process a task response for the workflow task.
        var result = soapClient.ProcessTaskResponse3(
            comments, 
            outcome, 
            spTaskId, 
            taskListName);

        // Check the results of the service operation.
        switch (result)
        {
            case ProcessTaskResponseResult.CannotObtainLock:
                // Cannot lock the workflow tasks for updating.
                retVal = false;
                break;
            case ProcessTaskResponseResult.InvalidUser:
                // Current user is not allowed to process a task response.
                retVal = false;
                break;
            case ProcessTaskResponseResult.Success:
                // Task response was successfully processed.
                retVal = true;
                break;
            default:
                // Unexpected response.
                retVal = false;
                break;
        }

        return retVal;
    }
    catch
    {
        // An error occurred while trying to process the task response.
        return false;
    }
}

Processing workflow data and to-do tasks

You can use the UpdateListItems service operation, in the Lists web service provided by SharePoint, to process task responses for workflow data or to-do tasks. Such tasks use the Status field in the task list to determine the outcome for a workflow task. For more information about using the UpdateListItems service operation, see Lists.UpdateListItems Method.

Processing Flexi task workflow tasks

Flexi task workflow tasks are generated by the Assign Flexi Task workflow action. Unlike other workflow tasks, a Flexi task workflow task can have a user-defined set of configured outcomes, which can be retrieved to validate an outcome prior to processing a task response for the Flexi task workflow task.

You can use the GetOutcomesForFlexiTask service operation to retrieve the set of configured outcomes for a given Flexi task workflow task, and, once an outcome has been validated, use the ProcessFlexiTaskResponse2 service operation to process the workflow task.

Example

The following example demonstrates how to use the GetOutcomesForFlexiTask service operation to validate a configured response before using the ProcessFlexiTaskResponse2 service operation to process a task response for a Flexi task workflow task.

public bool ProcessFlexiTaskResponse(
    int spTaskId, 
    string taskListName, 
    string outcome, 
    string comments)
{
    // Initialize the return value.
    bool retVal = false;

    try 
    {
        // First, validate the specified outcome against the set of valid configured
        // outcomes for the specified FlexiTask workflow task.
        var validOutcome = "";
        var outcomeList = soapClient.GetOutcomesForFlexiTask(spTaskId, taskListName);
        foreach (var configuredOutcome in outcomeList)
        {
            if(configuredOutcome.Name.ToLower() == outcome.ToLower()) 
            { 
                validOutcome = configuredOutcome.Name; 
            }
        }

        // Next, process the task response for the FlexiTask workflow task.
        if (validOutcome != "")
        {
            var result = soapClient.ProcessFlexiTaskResponse2(
                comments,
                validOutcome,
                spTaskId,
                taskListName);

            // Check the results of the service operation.
            switch (result)
            {
                case ProcessTaskResponseResult.CannotObtainLock:
                    // Cannot lock the workflow tasks for updating.
                    retVal = false;
                    break;
                case ProcessTaskResponseResult.InvalidUser:
                    // Current user is not allowed to process a task response.
                    retVal = false;
                    break;
                case ProcessTaskResponseResult.Success:
                    // Task response was successfully processed.
                    retVal = true;
                    break;
                default:
                    // Unexpected response.
                    retVal = false;
                    break;
            }

            return retVal;
        }
        else
        {
            // The specified outcome was not a valid configured outcome.
            return false;
        }
    }
    catch 
    {
        // An error occurred while trying to process the task response.
        return false;
    }
}

Processing workflow tasks by using task tokens

If you have a task token, provided by either a notification email or conversation from LazyApproval or a task stub from the GetTaskStubsForCurrentUser service operation, you can process a task response for the associated workflow task, even Flexi task workflow tasks, by using the ProcessTaskResponseUsingToken service operation.

If you have a task token, you can use the GetTaskDetailsUsingStub service operation to retrieve details about the workflow task represented by that task token, including the collection of available configured outcomes for that task, if that task token represents a Flexi task workflow task. This service operation allows you to validate a configured outcome prior to invoking ProcessTaskResponseUsingToken, without having to first identify the workflow task and then invoke GetOutcomesForFlexiTask.

Example

The following example uses the GetTaskStubsForCurrentUser and ProcessTaskResponseUsingToken service operations to process a task response for a workflow task by using a task token. The method determines whether the workflow task has configured outcomes (and is, therefore, a Flexi task workflow task), and processes the value of the outcome parameter accordingly.

public bool ProcessTaskResponseUsingToken(
    string taskToken,
    string outcome,
    string comments)
{
    try
    {
        // First, check if the task has configured outcomes by using the 
        // GetTaskDetailsUsingStub service operation. 
        // FlexiTask workflow tasks have to be handled differently
        // than other types of workflow tasks.
        ConfiguredOutcome[] customOutcomes = null;
        var taskDetails = soapClient.GetTaskDetailsUsingStub(taskToken);
        if (taskDetails != null)
        {
            customOutcomes = taskDetails.AvailableCustomOutcome;
        }

        // Depending on whether the task had available configured outcomes,
        // validate the specified outcome and process a task response using the
        // ProcessTaskResponseUsingToken service operation.
        if (customOutcomes != null)
        {
            // First, validate the specified outcome against the set of valid configured
            // outcomes for the specified FlexiTask workflow task.
            var validOutcome = 0;
            foreach (var configuredOutcome in customOutcomes)
            {
                if (configuredOutcome.Name.ToLower() == outcome.ToLower())
                {
                    validOutcome = configuredOutcome.Id;
                }
            }

            // Process a task response for the FlexiTask workflow task type, using the
            // ProcessTaskResponseUsingToken service operation and a task token.
            soapClient.ProcessTaskResponseUsingToken(
                comments, Outcome.Custom, taskToken, validOutcome);
        }
        else 
        { 
            // First, validate the specified outcome against the Outcome
            // enumeration.
            Outcome validOutcome = (Outcome)Enum.Parse(typeof(Outcome), outcome, true);

            // Process a task response for other workflow task types, using the
            // ProcessTaskResponseUsingToken service operation and a task token.
            soapClient.ProcessTaskResponseUsingToken(
                comments, validOutcome, taskToken, 0);
        }

        return true;
    }
    catch
    {
        // An error occurred while trying to process the task response.
        return false;
    }
}

See Also

Concepts

Workflow tasks

Operations

Working with workflow tasks

Reference

Web Service Reference