Workflows
Workflows
You can change how a certain process or workflow is approved in ERPNext by using workflows.
You can change and manage the steps for approving a document and changing its status with workflows. This means that you can make a multi-stage approval process with custom states, transitions, and role-based permissions that fit your business needs instead of the default Save-Submit-Cancel flow.
An ERPNext Workflow can have more than one level of approval. ERPNext needs you to fill out the Workflow conditions so that more than one person can make more than one request and have it approved by more than one user. Before submission, ERPNext keeps track of the different permissions.
So, if your process needs a lot of people, like junior staff making a request, a team leader approving it, and a manager giving final approval, you can make those roles and conditions clear. The system makes sure that each person only sees and acts on documents they are allowed to approve. This stops mistakes and changes that aren't allowed.
Think about a situation in which a quote needs to be approved by more than one person. A person with the "Sales User" role will make a quote. After that, a sales lead (user with the "Sales Manager" role) either approves or rejects it. If the sales lead approves it, the regional manager (user with the "Regional Manager" role) will either approve or reject it.
This example shows how you can make hierarchical approval workflows where each level of approval must do something before the document can move on to the next stage. This method lowers risk and makes people more responsible.
To make a Workflow and transition rules go to: - To set up Email Digest, go to:-
You can do things with a Workflow after it has been made by using Workflow Actions.
1. Requirements
It's best to make these first before making a Workflow:
• Actions in a workflow
Users can do these specific things (like Approve or Reject) at each step of the workflow. You can assign these actions correctly when you create a workflow if you set them up first.
• Workflow States such as Approved, Cancelled, and so on.
You need to list all the different states that your document can be in at different points in its life. These states are the points in your workflow where the document moves from one place to another.
2. How to Make a Workflow
• Click on New in the Workflow list.
• Give the Workflow a name and choose the DocType that it will be used on. This links your workflow to the type of document you want to control, like a quotation or a purchase order.
• Enter the different steps of the Workflow. Type in Doc Status for them, choose which field to change from the Update Field column, and then type in what the new value will be under Update Value.
These states show the document's lifecycle and help users quickly see where it is right now. Setting the Doc Status correctly also makes sure that ERPNext knows if a document is in Draft, Submitted, or Cancelled state on its own.
• Depending on the state, the Workflow States can be different colours. For example, green means success. There are three document statuses: saved (0), submitted (1), and cancelled (2).
Colour coding gives users a visual cue that makes it easier to quickly scan lists and timelines and see what the status of a document is.
• Workflow 4. Type in the Transition Rules.
These rules say when and how a document can change from one state to another. You tell the current state, the action that needs to be taken (like "Approve"), the next state, who can do this action, and any conditions that must be met.
Rules for Changing Workflows
You do the following in transition rules:
• Pick the Current State, which is the state the document is in right now.
• Choose the Action: the action that causes the state to change, such as "Approve" or "Reject."
• Set the Next State: This is the state that the document will go into after the action is taken.
• Assign Allowed Roles—decide which user roles can do the action in this transition (for example, only Sales Managers can approve a "Pending" quotation).
• Set Conditions, which are rules that limit the transition. For example, you could only allow approval if the total value is above a certain level.
• You can also use Next Action Conditions to make more complex workflow branching based on the data or context of the document.
This means that workflows can be changed to fit the needs of each business and show how they work.
2.2 Things to keep in mind when making a Workflow
Making a Workflow in ERPNext basically replaces the normal Save and Submit workflow. So, the document will work according to your Workflow and not the code workflow that was already set up. So if you don't say so in the Workflow you make, there might not be a Submit button or option.
It is very important to make sure that your workflow includes all the states and transitions that users need to be able to properly process documents (for example, submit and cancel). If these aren't there, users might get stuck or not be able to move documents forward.
If you don't apply a Workflow to a document and that document can be submitted, it will have the default workflow with the states: Draft, Submitted, and Cancelled. The user should take care of those default states if they are applying a Workflow to a document that can be submitted.
To keep the standard functionality, you need to make the same states and transitions for Draft, Submitted, and Cancelled in your workflow.
• You can't cancel a document until you send it in.
ERPNext makes sure that things happen in a logical order, so you can only cancel after you submit to keep document states from being inconsistent.
• You will need to write a workflow transition step that says "from submitted you can cancel" if you want to give people the option to cancel.
• If the fields in the Update Field column are not changed, a new custom field will be made with the name you put in the "Workflow State Field" field.
This means that ERPNext takes care of state tracking on its own by making a custom field if it needs to. This field keeps track of the current workflow state on the document.
2.3 Other ways to set up a Workflow
• Is Active: When this box is checked, all other Workflows for the chosen DocType stop working.
This makes sure that only one workflow is used at a time for each type of document, which prevents problems.
• Don't Override Status: The status of this workflow will not change the status of the document (Quotation) in the list view.
If you want to keep the original document status display instead of the workflow state in list views, choose this option.
• Send Email Alerts: The user will get emails with the next possible steps in the workflow.
This feature sends users an email to let them know about tasks that are due soon. This speeds up processing and stops bottlenecks.
3. Characteristics
3.1 Turn on or off the optional workflow state
Added in Version 12
In States, the optional Workflow state means that the state might not be included in the final approval.
For instance, you can make states like Cancelled or Rejected optional, which means that the document doesn't have to go through them to be finished. They are different end points or exceptions in the workflow.
Note: Workflow Actions can't be made for optional states.
This means that users don't have to do anything to move into optional states; transitions can happen automatically or through other means.
3.2 Requirements
You can also add a condition that must be met for the Transition to work. For instance, if a sales executive makes a quote with a total of $100,000 or more, a certain role must give their approval. You can set a property for Condition: to make this happen in this specific transition:
doc.grand_total is less than or equal to 100000
The field name of the field "Grand Total" in Quotation is grand_total. To find out the name of a field, go to Menu > Customise.
This makes it possible for the behaviour of the workflow to change based on the data in the document.
You can add this to any part of the document.
Version 13 added it
You can now use the date/time, session, getvalue, and getlist functions in your condition expressions in Version 13. This gives you powerful scripting tools to manage transitions in your workflow.
Allowed functions are:
• get_value from frappe.db
• frappe.db.get_list
• frappe.session
• frappe.utils.now_datetime
• frappe.utils.get_datetime
• frappe.utils.addtodate
• frappe.utils.now
For example:
doc.creation > frappe.utils.addtodate(frappe.utils.nowdatetime(), days=-5, asstring=True, as_datetime=True)
This example shows that the transition is only allowed if the document was made more than five days ago. These kinds of situations help make sure that deadlines or cooldowns are followed.
4. An example of how to approve a quote
When a sales user saves a quote, the document's status changes to "Draft." When they click "Submit," the status changes to "Approval Pending By Sales Manager."
(Workflow State in Transaction)
The Sales Manager can either approve or reject when he logs in. The document's status changes to "Approval Pending By Regional Manager" if it is approved.
(Choices for Workflow Actions)
The Regional Manager can finally "Approve" or "Reject" the quote when he opens it.
(Options for Workflow Actions)
This example shows how a multi-tier approval process works in real life. Each role only sees the actions that are relevant to their stage, which keeps things running smoothly and holds people accountable.
Tasks for Moving Workflows
Note:
This will be added in version 16.
Beginning
Workflow Transition Tasks are a great feature that lets you automatically do certain things when a Workflow changes from one state to another. This gives you more control over the lifecycle of your documents and makes automation easier.
There are Transition Tasks in the system that can be linked to each Workflow Transition, such as moving from "Pending" to "Approved." These tasks make sure that certain actions, like sending notifications, updating fields, or running custom code, happen right away or in the background whenever the transition happens.
You can control these tasks by connecting them to Workflow transitions using the Link to Workflow Transition Tasks option.