ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

Get next workflow state using API

I digged into the source code of frappe workflow and found this interesting method

My use case is to get this next_state variable for a particular state. How can I utilize this function, as the documentation for the same seems to be missing.

Thanks

Fetch Next Workflow State

In .js

frappe.get_children(frappe.workflow.workflows[doctype], "transitions", {
	state: state, action:action})[0].next_state

e.g.

frappe.get_children(frappe.workflow.workflows["Leave Application"], "transitions", {
	state:"Applied", action:"Review"})[0].next_state

In .py

frappe.db.get_value("Workflow Transition", {
	"parent": active_workflow_name,"state": current_state,"action": action
}, "next_state")

e.g.

frappe.db.get_value("Workflow Transition", {
	"parent": "Test Workflow", "state": "Applied", "action": "Review"
}, "next_state")
4 Likes

That was indeed very helpful, thank you.