Workflows
Using Workflows, you can define how a specific process is approved and governed in ERPNext.
- Workflows in the latest releases offer much greater flexibility, automation, and control by the users. You can now specify:
- Multiple approval levels for various documents.
- Conditional routing (e.g., amount-based, departmental approvals).
- Automated reminders and notifications.
- Direct action through email or in-app notifications.
This helps businesses to model their precise approval chain, eliminate delays, and ensure accountability.
You can have multiple levels of approvals in an ERPNext Workflow. For more than one user to be able to submit and more than one role to approve, ERPNext needs you to specify Workflow States and Transition Rules. ERPNext also logs all permission checks before submission.
For instance, in a Quotation Approval:
- A Sales User submits a quotation.
- A Sales Manager approves or rejects it.
- If approved, it goes to the Regional Manager for approval.
- This chain ensures that relevant documents are seen by the correct people at the correct time.
To create a Workflow and define transition rules, go to:
After creating a Workflow, you can act upon it through Workflow Actions.
1. Prerequisites
- Before you create a Workflow, ensure that you have:
- Workflow Actions (Approve, Reject, Request Changes, etc.).
- Workflow States such as Draft, Approved, Cancelled, Rejected, etc.
2. Creating a Workflow
- Navigate to the Workflow List, click on New.
- Provide a name for the Workflow and choose the DocType (e.g., Quotation, Leave Application).
- Specify the various states of the Workflow. For each state, set:
- Doc Status (Saved = 0, Submitted = 1, Cancelled = 2).
- Update Field (e.g., Workflow State).
- Update Value (e.g., “Pending Sales Manager Approval”).
- Visual tracking color code (e.g., Green = Approved, Red = Rejected).
- Specify the Transition Rules (who can advance a document from one state to the next, and under what criteria).
With the later versions, you can also:
- Add time-based transitions (e.g., auto-approve if pending > 3 days).
- Establish custom actions such as Send Back for Revision.
- Employ role-based restrictions so that only the authorized users can advance.
Workflow Transition Rules
- Transition rules specify who may do what at each step. For instance:
- Only a Sales Manager can transition a Quotation from “Draft” → “Pending Approval.”
- Only a Regional Manager can transition it from “Pending Approval” → “Approved.”
2.1 Points to remember while creating a Workflow
Creating a Workflow takes precedence over the system default Save/Submit process in ERPNext. What this implies is that now the document will follow your own custom Workflow rather than the system default.
Example: if you do not define a “Submit” step, the Submit button will not be displayed.
If a document type has a default workflow (e.g., Draft → Submitted → Cancelled), and you override this with a custom Workflow, you need to include these states in your custom Workflow if you wish to have them.
Important points:
- A document can only be cancelled if it has previously been submitted.
- If you wish users to cancel, you should specifically set a transition (Submitted → Cancelled).
- If Update Field is left empty, ERPNext will create a new custom field named “Workflow State.”
2.2 Other options for a Workflow
- Is Active: Enables the Workflow. When active, all other Workflows for the same DocType are inactive.
- Don’t Override Status: Displays the original document status (e.g., Draft/Submitted) in list view in addition to the Workflow state.
- Send Email Alerts: Emails (and in-app alerts in newer releases) the user to take the next required action.
3. Features
3.1 Enable/Disable Optional Workflow State
(Introduced in Version 12)
- A number of Workflow States can be flagged as optional, i.e., they don’t need to be part of the final approval path.
Example:
Rejected or Cancelled states can be there but are not required in order for the document to finish its life cycle.
Warning:
Workflow Actions are not created for optional states.
3.2 Conditions
You can include conditions to specify when a transition is acceptable.
Example:
- If a Quotation is created with a Grand Total ≥ $100,000, then it has to be approved by a Regional Manager.
- If less than $100,000, then it can be approved by the Sales Manager.
Condition syntax example: doc.grand_total <= 100000
- To verify field names, navigate to Menu > Customize Form.
Added in Version 13 and subsequent improvements: You are now able to use functions such as date/time, session values, getvalue, getlist in condition expressions.
The following functions are permitted:
- frappe.db.get_value
- frappe.db.get_list
- frappe.session
- frappe.utils.now_datetime
- frappe.utils.get_datetime
- frappe.utils.addtodate
- frappe.utils.now
Example:
doc.creation > frappe.utils.addtodate(frappe.utils.nowdatetime(), days=-5, asstring=True, as_datetime=True)
This flexibility enables very powerful and dynamic approval conditions.
4. Example of a Quotation Approval Process
- A Sales User saves a Quotation → Status: Draft.
- On Submit → Status changes to Approval Pending by Sales Manager.
- The Sales Manager logs in → can Approve or Reject.
- If approved → goes to Approval Pending by Regional Manager.
- The Regional Manager approves and gives final approval.
- If approved → Status = Approved.
- If rejected → Status = Rejected.
- This makes sure all essential quotations get double-checked before finalization.
5. Video
- (Attach link to latest tutorial video if available in ERPNext docs/YouTube.)