Server

HOWTO: Query Workflow Objects

Updated: March 18, 2024

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

Query all running workflows:

SELECT * FROM DocumentRoute WHERE ecm:currentLifeCycleState = 'running'

Query all available workflow models:

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 documents
  • rnode:variablesFacet for nodes.

So both workflow and node variables can be queried as any other Nuxeo property.

Query all running default serial workflows, having the global variable "initialComment" set to "test"

SELECT * FROM DocumentRoute WHERE var_SerialDocumentReview:initiatorComment = 'test'  

Query all running workflows for a given document

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

Query for all opened tasks

SELECT * FROM TaskDoc WHERE ecm:currentLifeCycleState = 'opened'