Workflow
Workflows allow you to define and control the approval process of a document in ERPNext. They help you customize how a document moves through different stages such as Draft, Approval, Approved, or Rejected.
1. Overview
With workflows, you can define multiple approval levels for a document and assign them to different roles. Each transition between states can have conditions, permissions, and actions.
Example: A Quotation may require approval from a Sales Executive → Sales Manager → Regional Manager before final approval.
Go to: Home > Settings > Workflow
2. Prerequisites
Before creating a workflow, it is recommended to set up:
- Workflow States (Approved, Rejected, etc.)
- Workflow Actions
3. How to Create a Workflow
- Go to Workflow list and click New.
- Enter Workflow name and select DocType.
- Define Workflow States with:
- Doc Status (0 = Draft, 1 = Submitted, 2 = Cancelled)
- Update Field and Update Value
- Define Transition Rules between states.
3.1 Notes
- Workflows override the default Save/Submit flow of a document.
- If no Submit action is defined, the Submit button will not appear.
- Cancel action must be explicitly defined in transitions.
- If Update Field is not set, a custom field may be created automatically.
3.2 Workflow Options
- Is Active: Activates this workflow and disables others for the DocType.
- Don’t Override Status: Keeps original document status unchanged in list view.
- Send Email Alerts: Sends notifications for next workflow actions.
4. Workflow Features
4.1 Optional States
Some workflow states (like Cancelled or Rejected) can be marked as optional.
These are not part of the main approval flow.
4.2 Conditions
Transitions can include conditions based on document fields.
Example:
doc.grand_total <= 100000
Advanced conditions can use date/time functions and database utilities such as:
- frappe.db.get_value
- frappe.db.get_list
- frappe.session
- frappe.utils.now_datetime
- frappe.utils.add_to_date
5. Example: Quotation Approval Workflow
A Quotation moves through multiple approval stages:
- Sales User creates the quotation (Draft)
- Sales Manager reviews and approves/rejects
- Regional Manager gives final approval
Each stage updates the document status and restricts available actions.
6. Related Topics
- Workflow Actions
- Assignment Rule