How to filter Link field in query report based on other field

Hi All,

I am new to ERP Next. i am preparing a script report with filters. I have two link fields in the filters, one is to load states another one is for districts. Now i want to display the districts list in the filter based on the selected state. can anyone suggest how can i achieve that?
For Eg: If i select Kerala in state filter then when i click on the district it should display only districts from kerala not from other states.

Thank you

Hello @ERPNext_Usr

I’ve written a tutorial on doing just this but for a Script Report : [Tutorial] Script Report / Chart - #14 by EugeneP

Hi
Thank you for your reply and tutorial which is very good.
I tried the filter part but unfortunately it wasn’t working for me please suggest

{
“fieldname”:“state_code”,
“label”:(“State”),
“fieldtype”:“Link”,
“options”:“StateList”,
“width”:100,
“reqd”:0,
on_change: function(query_report){
query_report.set_filter_value(‘district_code_data’, []);
console.log(“State code selected …”)
query_report.refresh();
}
},
{
“fieldname”:“district_code_data”,
“label”:
(“District Code”),
“fieldtype”:“Select”,
“width”:100,
“reqd”:0,
get_data: function(txt) {
console.log(“get_data_executing”)
if (frappe.query_report.get_filter_value(‘state_code’)) {
var name = frappe.query_report.get_filter_value(“state_code”);
console.log(name)
return frappe.db.get_list(“Employee”, {fields: [‘district_code’], filters: {“state_code”: name}, distinct: 1});
//return frappe.db.get_link_options(“Activity Log”, txt, {“user”:name});
}
else {
console.log(“Else condition…”)
return [];
};
},
on_change: function(query_report) {
console.log(“On change district code…”)
query_report.refresh();
},

	},