Workflows are stored in Nuxeo as documents of type "DocumentRoute". A workflow instance is created by copy from a workflow model. The lifecycle state for a workflow model is "validated", while the instances can be "running", "done" or "canceled".
A node in the workflow is stored as a document of type "RouteNode". A node has an unique id generated by Studio, set on the
rnode:nodeId property. Nodes can be automatic steps or nodes of type task. If a node is of type task, that means a task (persisted by default as a document of type TaskDoc) is created when the workflow is executing that node. The workflow will be resumed only when this task is completed.
Since workflows, nodes and task are all documents, the NXQL query language can be used, like on any other document type.
Using Lifecycle State
SELECT * FROM DocumentRoute WHERE ecm:currentLifeCycleState = 'running'
SELECT * FROM DocumentRoute WHERE ecm:currentLifeCycleState = 'validated'
Using Workflow and Node Variables
Both workflow and node variables are persisted on the workflow and node documents. These are metadata stored on a dynamic facet, in a schema named as following:
- for workflow variables, the name of the schema (and its prefix too) is
- for node variables, is
The name of this facet is stored as the property:
docri:variablesFaceton the workflow documents
So both workflow and node variables can be queried as any other Nuxeo property.
SELECT * FROM DocumentRoute WHERE var_SerialDocumentReview:initiatorComment = 'test'
SELECT * FROM DocumentRoute WHERE docri:participatingDocuments IN ('$docId') AND ecm:currentLifeCycleState = 'running'
Querying Workflows Suspended at a given Step
NXQL queries can reference any metadata. Using the CoreSession#queryAndFetch API we can look for workflows suspended on a given step. This will return in an IterableQueryResult the id of the document representing the workflow document.
SELECT ecm:parentId FROM RouteNode WHERE rnode:nodeId = 'Task5237' AND ecm:currentLifeCycleState = 'suspended'
where 'Task5237' is the unique id of the node.
Querying Workflow Tasks
SELECT * FROM TaskDoc WHERE ecm:currentLifeCycleState = 'opened'