Script Report Filter Customisation


I want small help from you guys.

I have added 4 filters in my script report and it works fine. But i want to improve in some how.

Like there are 4 filters.

  1. From Date
  2. To Date
  3. Department
  4. Employee

Now if i select department then in Employee filter, i only want to show employee which belongs to selected department. What should i do to achieve this ?

Here is my Code.

	    "fieldname": "department",
            "label": __("Select Department"),
            "fieldtype": "Link",
	    "options": "Department"

	    "fieldname": "employee",
            "label": __("Select Employee"),
            "fieldtype": "Link",
	    "options": "Employee"

Thanks & Regards,
Hardik Gadesha

1 Like

Any Help From You Guys ?

Try to use get_query in your JS for filtering.

Thanks for the quick reply @Pawan.

Can you elaborate this please ? i didn’t get you.

		"label": __("Select Employee"),
		"fieldtype": "Link",
		"options": "Employee",
		"get_query": function() {
			return {


And in py you can write a query to get what you want under filters condition:

def get_employee(doctype, txt, searchfield, start, page_len, filters):
    return frappe.db.sql(""" select name from `tabEmployee` where department='{0}' """.format(filters.department))

Thanks @OmarJaber,

What is the meaning of this doctype, txt, searchfield, start, page_len, filters ? am i need to make changes according to my Doctype/ Report or keep it same as given ?


It Throws error while selection employee filter.

return frappe.db.sql(“”" select name from tabEmployee where department=‘{0}’ “”".format(filters.department))

Error :

AttributeError: ‘NoneType’ object has no attribute ‘department’

What are the mistakes and changes ?

1 Like

“fieldname”: “employee”,
“label”: __(“Select Employee”),
“fieldtype”: “Link”,
“options”: “Employee”,

“get_query”: function() {
var department = frappe.query_report_filters_by_name.department.get_value();
return {
“doctype”: “Employee”,
“filters”: {
“department”: department,


Thanks @magic-overflow,

It’s working :slight_smile: