Try ERPNext Buy Support Partners Foundation

Filter Links Data in Child Table


I want to filter data on child table,
I’ve Child Table named ‘BS Tracking Reviews’
BS Tracking Reviews have field ‘balance_sheet’ which is linked to Doctype named ‘Heads’
in Heads i’ve field named ‘client’ and i also have ‘client’ field in Parent doctype named “Tracking Reviews”.
I want to filter Heads Data in Tracking Forms, according to clients.

Find below images for reference.

I’ve tried below script but it is not working.

frappe.ui.form.on("BS Tracking Reviews", {
	balance_sheet: function(frm,cdt, cdn){
		data_filteration(frm, cdt, cdn);
var data_filteration = function(frm, cdt, cdn) {
    var child = locals[cdt][cdn];
		frm.set_query("child.balance_sheet", function() {
			return {
				filters: [
					["Heads","client", "in", [frm.doc.client]]

try this
--------------------on .js-------------------------------------

        frappe.ui.form.on(“Doctype Name”, “onload”, function(frm) {
        frm.fields_dict.childtablename.grid.get_field(‘child_field’).get_query =
        function() {
        return {

        	query: "appname.appname.doctype.doctypename.doctypename.methodname",
        filters: {


    --------------------------on .py--------------------------------------------------
       def methodname(doctype, txt, searchfield, start, page_len, filters):
       	return frappe.db.sql(""" your query """.format(code= filters.get("client")))

Thanks @PrashantPatil i’ll try and feed you back.

work like a charm

Hello @pratikcws @shahid @PrashantPatil,

I tried your solution for filter links data in child table and it pretty much worked for me. The bad thing which is happening is you have to manually select the option from the Link field.

A normal link field has all the data and works like a charm with suggestions when typing the name of data. It sorts too using like operator and so on.

I want this to happen in your solution too with suggestions when a user manually types the data.

Can anyone help me out?
Thanks in advance!

It would be of great help if anyone can drop any hints/path to achieve this. :grinning:

Hi rohan,
You can do this by adding like condition in your query.
frappe.db.sql("your query ......and month like '{1}' """.format('%%%s%%' % txt))


very simple

first do this in your js{
freeze: true,
args: {
“project_name”: cur_frm.doc.project,
“building_name”: cur_frm.doc.building_name
callback: function(serialno){
var includeinarray = []

	cur_frm.set_query("serial_no", function() {
        return {
            filters: [
			 ['Serial No', 'serial_no', 'in', serialno.message],

and add this code in py

def filter_serialno(project_name,building_name):
	sn_list = frappe.db.sql("""select pu.final_serial_number as name from `tabPlot Unit Price` as pu LEFT join `tabGenerate Sales Unit` as gs on where gs.project_name=%s and gs.sel_building_name=%s""",(project_name,building_name),as_dict=1)
	return [ for x in sn_list]
1 Like