V13-How to default the filter value in Query reports

All,
I am trying to build a custom query report in V13. Query report now allows us to define the filters. However I am not able to default the value of filters.
For eg I want to default the value of date_from and date_to to month start and month end.


There is no option to give the default values.

There is a script section in the query report. Could someone show how to use this feature. For example how to manipulate the result from the query

1 Like

I have the analysed the frappe framework on how the reports are being executed. frappe/query_report.py at develop · frappe/frappe · GitHub.
the code executes query in the query section with filter if it is a query report else runs with the script in the script section.
So when you choose the option as script report client script section will open.

Here is a little hack. Maybe this is a bug. For now i am using this bug to my favour.
You can define the filter here with default values in the client script section like below


save the report. Run the report once to get the filter value

now switch back the report type to query report.
now use the filters as usual. Note please don’t define the filters in the filter section.

4 Likes

Hi @gsarunk

as you mentioned i will tried but it throws error .
I removed the filters field.

You will need to add “Options” in the filters

{
“fieldname” : “employee”,
“fieldtype” : “Link”,
“options” : “Employee”,
“default”: “default_employee_id”,
…
}

Hi @Nirvisha_Soni
Thanks for your reply

I have changed but still loading screen only showing.

Have you added “Columns”?

Yes I have added columns

in System console this is executing

in Query att.employee AS “employee” ,<-- here you will have to add the fieldname that you have added in the columns table.
Also specify other Columns as well.