How to fetch the status list value to filter any doctype? like material request

How to fetch the status list value to filter any doctype? like material request

import frappe

Fetch distinct Status and Workflow State values from the Asset Request doctype

status_values = frappe.get_all(“Asset Request”, distinct=True, filters={“status”: (“is not”, None)}, pluck=“status”)

workflow_state_values = frappe.get_all(“Asset Request”, distinct=True, filters={“workflow_state”: (“is not”, None)}, pluck=“workflow_state”)

Pass Status and Workflow State values to the HTML template

context.status_values = status_values
context.workflow_state_values = workflow_state_values

Thanks and Regards
Shubham

In python, you can use frappe.get_meta to accomplish this, which will return customizations to the Status field appropriately.

frappe.get_meta("Material Request").get_field("status").options.split("\n")

If you did a similar lookup with DocField, it would not include any customizations.

frappe.get_value("DocField", {'parent': "Material Request", 'fieldname': 'Status'}, 'options').split('\n')

If you’re looking for the various states of a workflow there are a couple of possibilities. From the frontend, it is possible to access them with any of a couple of functions in frappe.workflow depending on if you only want valid states or if you want an entire list.

On the back end there are similar APIs, but since you want them in an HTML template, I would use the JS API.

Thank you buddy @tmatteson
It’s working perfectly

HTML

Status:

All {% for status_option in status_options %} {{ status_option }} {% endfor %}

and

Python Scripting

Fetch the Asset Request DocType

asset_request_doc = frappe.get_meta(“Asset Request”)

Get the options for the ‘status’ field

status_options = asset_request_doc.get_field(“status”).options.split(“\n”) if asset_request_doc else []

Pass the status options to the HTML template

context.status_options = status_options

where, Asset Request is my custom doctype

can see the output here

Thanks and Regards
Shubham

1 Like