The first part is the introduction and terminology overview (which is vital for understanding workflows). If you want to skip straight to the demo then head to post number 2.
Introduction
Workflows are one of the most powerful features of Mayan EDMS. When utilised effectively they can be used to automate almost any business process, as well as to customise Mayan EDMS and the documents within it to your liking.
However, with great power often comes an increased learning curve. Workflows can take a bit of practice to optimise to your requirements. This guide is designed as a primer or introduction to workflows. I'll walk you through the basic concepts of the workflow process and how it all fits together, and then we'll produce a sample workflow to send an email upon every document upload to a user as a simple example that you can modify to suit your needs.
Note: Everything here, along with a whole lot more, is covered in the Exploring Mayan EDMS Book. I encourage everyone to consider purchasing a copy to get a more complete picture of workflows and a lot more. This forum guide is aimed as companion material to the book. It also has the added benefit of directly supporting the project, which allows us to continue adding the features you desire, fix the bugs you need fixing and provide the free support on the forum (I hope) you benefit from

Very important note: The Mayan EDMS team have experience designing and implementing workflows to solve all sorts of business needs. You can give your Mayan EDMS installation a quickstart by considering a Mayan EDMS support plan, where you can get expert advice on workflows or any other topic relating to Enterprise Document Management. The team are also available for consulting engagements to get you up and running even faster. They're able to set up the foundations and produce documentation & training material for your teams so that they're empowered to set up their own workflows relevant for their own team & processes. That's in addition to helping you set up a production ready environment suitable for your critical workloads. Head to https://www.mayan-edms.com/support/ or email sales@mayan-edms.com to enqure about this.
Workflow terminology
It helps us to first define some terms which I'll refer to continually throughout the tutorial.
Workflow: Implemented using Mayan's Finite State Machine, Workflows are a collection of States, Transitions (between States), Actions (to take when a Transition happens) and Triggers (that invoke a Transition). The ultimate purpose of a Workflow is to perform a process. That could be a Business Process (such as approving a document), a Change (such as adding a tag to a document) or a Transformation (to modify a document in some way, such as adding a redaction). A Process can really be anything you desire to automate. In the example shown below the Process is "send an email whenever a user uploads a new document". Some other good examples:
- Change a documents ACL to be world readable when the metadata label "Visibility" has it's value changed to "Public"
- Email Accounts Payable when a document type "Purchase Order" is created, but only when that document has the tag "Pending Payment"
- When the metadata value of "Paid" is added to any document of the type "Pending Invoice", change the document type to "Paid Invoice", add a tag with the value of "Paid" and add today's date to the Documents metadata with a metadata label "Date Invoice Paid"
- Any document uploaded into the document type "Hiring Offer" get's automatically tagged as "Pending". When a document is first marked as "Pending", email the L1 approver the document and ask for approval. Once the L1 approver has entered the workflow and marked the document as "Approved", change the progress to 50% complete and email the L2 approver for approval. Once the L2 Approver marks the document as "approved" in the workflow, email a copy of the document to Human Resources and also email a copy of the document to the email address defined with the metadata label "Prospective Employee Email Address". Once Human Resources have confirmed acceptance of the document by the Prospective Employee, they mark the document as approved in the workflow, at which point the tag "pending" is removed, today's date is added to the metadata label "accepted date", and the tags "archived" and "accepted" are added.
States: A state is the current position of a Document within a workflow. Being a finite state machine, a document can only be in one state in a workflow at any point in time. Each workflow should have an initial state that the document starts in, and as various Transitions occur (which are invoked by Triggers) a document will move through the various states. States are associated with a % of completion of a specific workflow. As a document moves through a workflow it progresses towards the final state, which is 100% completion. However, different transitions can move a document towards the 100% completion state or take it backwards to a previous % completion state. One example of this:
1. Document enters the workflow at 0% Completion. This is marked as the initial state.
2. A document gets approved by a L1 manager and a Transition moves it to another state which is marked as 30% Completion.
3. The L2 manager rejects the document at this stage in the workflow, which depending on the requirements of the process could move the Document to the 100% completed state but add a Tag "Rejected" (using an action) OR it could move it back to 0% Completion and add the tag "Rejected" ready for someone to upload a new version of the document and start the process again.
Actions:
When it comes to States, a Document is either going to be stationary in a State, entering a State or exiting a State. This is where actions come in.
An action can happen when a document Enters, Exits a state or both. You can assign multiple actions to a state. Each action invokes a specific automated task. Here's the full list of possible actions that can happen when a document enters or exits a state:

One of the more powerful actions is the "Perform a POST request". This allows you to invoke ANY API, either one of Mayan's or any external API.
This means you can integrate your actions and workflows into any existing piece of software that has a workflow.
To give an example I use at my Organisation:
1. A customer orders from our website. When the order is completed an invoice is generated which is uploaded into Mayan into the "Pending Orders" document type. It's a customer order form for a cloud based product we offer. In the document metadata they've described various things about their purchase (such as size of the virtual machine and AWS region they want to launch the product into).
2. The workflow initial state is 0%. On entering that state (which happens automatically to all "Pending Orders", there is an Action that assigns the "Payment Pending" tag automatically
3. Our payment processor can send webhooks upon successful payment. We have it set up so that when payment is successful a webhook to the Mayan EDMS API is called that adds a tag "Payment Confirmed"
3. We have a transition trigger set (more on that below) that monitors for new Tags added. When it spots the "Payment Confirmed" tag added to the document it transitions it to the 50% Complete "Provisioning" State
4. As an entry Action to the Provisioning State, we've set up the "Perform a POST request" Action to send a POST to the AWS API that deploys the infrastructure. As everything in Mayan EDMS is templateable, we use the values the customer provided in the order (which is saved as document Metadata) as some of the variables in the POST request
5. The document is in the Provisioning state. A second Action we have as a document enters that state is to email our service desk that a new order is provisioning. That team will go and investigate the built environment to do a manual check before signing it off. During the time it takes them to get the email and check the environment the previous POST has already completed successfully and it's build
6. They manually progress the document to the 100% Provisioned state. This causes the document to Exit the Provisioning state and we have an Action set up on Exit from the Provisioning State to send an email to the customer (using metadata from the document again to get their name and email) saying their environment is ready to go and here are their credentials.
That's one example of what looks like a complex workflow, but only took a hour to implement and works reliably. It goes to show how diverse workflows can be!
Transitions:
Transitions move Documents from one state to another state. It is how we take a document from 0% Completion to 30% Completion to 100% Completion.
Transitions always have an Origion State (what state the document is transitioning from) and a Destination state (what state the document is transitioning to). Transitions do not have to be linear (as in 10% > 20% > 30% etc) and can have any origin or destination state. A workflow can have as many transitions as you require. This gives an unlimited number of combinations of states, transitions and actions and allows for complete customizability to suit your workflow process needs.
Fields: Transitions can be assigned Fields. These are pieces of additional metadata that provide context to the transition. They can be used for example to add internal notes to a transition or ask someone executing a transition a question. You can use the value of a field in any other part of a workflow, and the field data will always be associated with a specific workflow execution for a specific document but will not become a part of the document itself.
Transition Triggers:
Users can invoke a Transition on a document manually, but Transitions can also be configured to happen automatically. This is one of the core features of Mayan's automation.
Triggers are events that invoke a Transition (which moves a document to a different state, potentially invoking that states exit or entry action as it does so).
Almost anything that creates an event in Mayan can be used as a transition. Here's some examples taken from Mayan:

A transition can have multiple triggers enabled for it and any time any of those enabled events happen the transition will trigger. Remember a workflow can have multiple transitions associated to it and each transition can have any number of triggers that invoke that transition.
As I hope you're starting to see, the potential power and sheer flexibility of Workflows is why I recommended Mayan EDMS Support and Consulting earlier on. You really can achieve anything you want to with workflows.
Events:
Just like most things in Mayan, an event is logged any time a transition is triggered or action happens as the result of entering or exiting a State. You can subscribe to these events to be notified when they happen.