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.
Querying Workflows
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
var_$WorkflowModelName
, - for node variables, is
var_$NodeId
.
The name of this facet is stored as the property:
docri:variablesFacet
on the workflow documentsrnode:variablesFacet
for nodes.
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'