Nuxeo Studio Rocks! Route Your Workflow Based on Document Metadata

Wed 09 September 2015 By Thibaud Arguillere

Nuxeo Studio RocksNuxeo Studio rocks! It’s a fact!(1)

Today, Nuxeo Studio will rock by helping us easily (in five, maybe ten minutes) implement an important business rule in our Nuxeo application. Suppose this is our challenge:

I want my workflow to automatically proceed via one route or another, depending on the value of some document metadata fields.

This blog describes one way of doing so; one way among many others.

By the way, each article in the “Nuxeo Studio Rocks” series always comes with a playlist. Since I just wrote “one way” two times(2), let’s start the musical ambiance by listening to Status Quo, The Way it Goes. I hope you enjoy it!

The main principles to this solution are:

  • Have a simple "Node", with a String Node Variable

  • Have 1-n transitions from this node. For each transition, the "Condition" field checks the value of the Node Variable

  • In the "Input Automation Chain" of the node, have a chain filling the Node Variable, depending on the metadata

Let’s build this using Nuxeo Studio’s Workflow Editor.

For this example, we will keep everything simple, because Simple is Beautiful(3). So we have a basic Node (from the “Automated Tasks” topic), with two transitions that we name route1 and route2. Each transition goes to an “Approve” User Task:

This simple Node has the following properties:

  • In the “Variables” tab, add a new variable, type string, name (in my example) whichRoute

  • In the "Transitions" tab, we have two transitions:

    • One is named “route1” and has the following expression as “Condition”: @{NodeVariables["whichRoute"] == "route1"}

    • The other is named “route2” and has the following expression as “Condition”: @{NodeVariables["whichRoute"] == "route2"}

You can see the conditions test the value of whichRoute. All we have to do now is to write the Automation Chain that fills the value of whichRoute depending on the document’s metadata. Now, still in the node’s properties dialog:

  • Go to the "General" tab

  • In the "Select Input Automation Chain" area, click "Create"

  • Give a name to the new Chain. AutoDispatchRoute in our example.

Here is the chain:

  • Note, in this example, I am choosing the route depending on the value of the dc:format field. This is where you would check your own field(s).

  • Important: A workflow always handles a list of documents, not a single one. In this example, it receives a list of one single document, but still a list. This is why I am using Restore input document from a script. See here for a bit more detail.

Fetch > Context Document(s)
Execution Context > Restore input document from a script
script: This[0]
Workflow Context > Set Node Variable
name: whichRoute
value: @{Document["dc:format"] == "JPEG" ? "route1" : "route2"}

All together in a very nice schema:


Save, deploy on your test server. Now, when you start a workflow on a document, depending on the value of the dc:format field, it will follow route1 or route2.
That was easy, wasn’t it?

(1) Not an opinion. Just a fact. Like “Status Quo is the Best Rock Band Ever”.
(2) Three if you count this one!
(3) As probably once said by someone very important, interesting and well known!

Category: Product & Development
Tagged: How to, Nuxeo Platform 7.x, Nuxeo Studio