The sub-workflow functionality is the ability to call a workflow from another workflow (creating inception-like workflows), and to pass its variables along the way. The main workflow is suspended while the sub-workflow runs, and resumes when the sub-workflow ends.
This functionality is a great asset as it allows you to reuse your workflows and imagine powerful combinations. The best point is that you can dynamically choose the sub-workflow that should be called using an MVEL expression.
The company SuperTech wants to implement an expense report validation workflow, with the following rules:
- Users should be able to fill in their expenses and attach the corresponding receipt.
- Each expense should be validated separately.
- Expense type can be chosen from a list (transportation, hotel or misc).
- Expenses of 100 dollars or more have to be validated by the accounting service and the general manager, only by the accounting service if less.
- If the document is validated, set its status to approved.
- If the document is rejected, end the workflow.
Easy! We will take advantage of the sub-workflow functionality introduced in Nuxeo 5.7.2.
- The user will call a workflow.
- Depending on the document values, we will call a sub-workflow with the corresponding steps.
- The sub-workflows will be made generic so that they can also be used in another context.
This project will be divided in three steps:
- Creating the Expense document type
- Creating the validation sub workflows (called automatically depending on the document values)
- Creating the main workflow (called by the user)
Ready? So let's start with the Expense document type creation.