Nuxeo Server

How to Modify a Workflow Variable outside of Workflow Context

Updated: November 13, 2017 Page Information Edit on GitHub

A workflow (route instance) is stored in Nuxeo as a document of type "DocumentRoute". A node in the workflow is stored as a document of type "RouteNode". Both workflow and node variables are persisted on the workflow and node documents.

If you want to modify these variables outside of the workflow context (from a listener for example), you have to fetch the workflow instance document and you can use the available methods on their adapters, GraphRoute and GraphNode:

void setVariables(Map<String, Serializable> map);
Map<String, Serializable> getVariables();


GraphRoute route = doc.getAdapter(GraphRoute.class);
GraphNode node = route.getNode(nodeId);

You can either listen to events triggered on the document following the workflow, or on workflow events. In the first case, in the event handler you have the document following the workflow and you have to get the workflow instance document. Use the following method on the DocumentRoutingService service:

List<DocumentRoute> getDocumentRoutesForAttachedDocument(CoreSession session, String attachedDocId)

For the second case, the workflowTaskCompleted event is triggered during a workflow every time a task is completed. On this event, the id of the workflow (route) instance documents is directly added into the map holding the properties of this event. Here is some sample data fetched with my debugger on a break point on TaskEventNotificationHelper notifyEvent method:

event: workflowTaskCompleted
{category=eventDocumentCategory, sessionId=default-6778825317969559609, recipients=[Administrator, Administrator, test],
comment=szss, repositoryName=default, [email protected], documentLifeCycle=project}

taskVariables: {createdFromTaskService=true, taskNotificationTemplate=myTemplate, document.routing.step=0be590a5-8d03-48ef-9649-a82f06d8001a,
nodeId=Taska2e, documentRepositoryName=default, routeInstanceDocId=d05b14e4-8d60-41be-bea2-0d4063196c0b, directive=Aknowledgement, validated=false,

So if you want to set a workflow variable from a listener listening to workflowTaskCompleted event:

  1. Get the taskInstance from the eventProperties map.
  2. Get the workflow document (using his id = "routeInstanceDocId") from the taskVariables.
  3. Adapt the document to GraphRoute.
  4. Use setVariables like in the first example.

5 days ago manonlumeau Added content-review-lts2017 label
a month ago manonlumeau NXDOC-1346-FT review screenshot
3 years ago Manon Lumeau 17
3 years ago Manon Lumeau 16
3 years ago Manon Lumeau 15
4 years ago Solen Guitter 14
5 years ago Solen Guitter 13
5 years ago Mariana Cedica 11
5 years ago Mariana Cedica 12
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 5
5 years ago Mariana Cedica 6
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