Nuxeo Server

How to Complete a Workflow Task Programmatically

Updated: November 13, 2017 Page Information Edit on GitHub

You might need this to implement some sort of automatic processing instead of having the user completing the task from the UI.

Basically, you have to call:

    void endTask(CoreSession session, Task task, Map<String, Object> data,  String status) throws ClientException;

on the DocumentRoutingService , where:

  • task is the Task to end;
  • data is a map of variables. If a variable called "comment" is contained in this map, its value will be logged by the audit service under the "workflowTaskCompleted" event. When a user submits the task form (configured via Studio), this map contains all the variables in the form; If you want to set an existing Workflow or a Node variable when completing the task you can add them into this map.
  • status is the id of the button the user would have clicked to submit the task form (if the outgoing transitions of the workflow node that created the task have conditions depending on it). This id is the button id you specified when you configured the task form in Studio.

In your graph, you have nodes and transitions between these nodes. When the workflow enters a node, if that node is of type Task (that means is not an automatic one, like Start and Stop for example), a task is created at that step. This task is persisted as a document model, that can be adapted to the Task object. When a task is ended, the workflow is resumed. The task is holding information about the node and the workflow instance it was created from, so when the task is ended using the API above, the related workflow instance is resumed.

To fetch all the open tasks assigned to a given user, on a document use:

  List<Task> getTaskInstances(DocumentModel dm, NuxeoPrincipal user, CoreSession coreSssion) throws ClientException;

on the TaskService.

To fetch all the open tasks originating from the same node in the workflow use:

List<Task> getAllTaskInstances(String processId, String nodeId, CoreSession session) throws ClientException;

where:

  • processId is the id of the document representing the workflow instance.
  • node id, is a unique identifier of that node in the workflow, generated by Studio. It's listed on the General tab, on the node popup-up when editing a workflow node in Studio.

For some detailed examples on how to use this API, you can check the JUnit tests in the GraphRouteTest.


5 days ago manonlumeau Added content-review-lts2017 label
a month ago manonlumeau NXDOC-1346-FT review screenshot
a year ago Manon Lumeau 36
2 years ago Manon Lumeau 35
3 years ago Solen Guitter 34 | Fix links to point to latest version
3 years ago Manon Lumeau 33
3 years ago Manon Lumeau 32
4 years ago Solen Guitter 31
4 years ago Solen Guitter 30 | Updated links
4 years ago Mariana Cedica 29
4 years ago Solen Guitter 28
5 years ago Solen Guitter 27
5 years ago Solen Guitter 26
5 years ago Mariana Cedica 25
5 years ago Mariana Cedica 24
5 years ago Mariana Cedica 22
5 years ago Mariana Cedica 23
5 years ago Mariana Cedica 21
5 years ago Mariana Cedica 20
5 years ago Mariana Cedica 19
5 years ago Mariana Cedica 18
5 years ago Mariana Cedica 17
5 years ago Mariana Cedica 16
5 years ago Mariana Cedica 15
5 years ago Mariana Cedica 14
5 years ago Mariana Cedica 13
5 years ago Mariana Cedica 12
5 years ago Mariana Cedica 11
5 years ago Mariana Cedica 10
5 years ago Mariana Cedica 9
5 years ago Mariana Cedica 8
5 years ago Mariana Cedica 7
5 years ago Mariana Cedica 6
5 years ago Mariana Cedica 5
5 years ago Mariana Cedica 4
5 years ago Mariana Cedica 3
5 years ago Mariana Cedica 2
5 years ago Mariana Cedica 1
History: Created by Mariana Cedica