Question about frm.set_query for fields in child table

Hi

I have an issue on setup query for my child table in my form of my app.
First of all like in my snapshot below, my child table Items has field called Delivery Note ID which is linked to document Delivery Note. i had set_query code in my custom script, but there is no effect in editable mode
image
As you can see filters applied for Name in is nothing.
but if I click the edit button if this row, in detailed mode I can see the filters correct.

second, if I change the value of field Item Code, still in detailed mode, the filters still maintain the last status, won’t change accordingly (my custom script has code to change it if Item Code changed)
but if I return back to child table and click edit again, then the filters applied correct.

So I don’t know why and how to resolve it?

Thanks.

My erpnext version is 13.19.0, same as frappe version.

@ithelpdesk where exactly you are writing the js code ?

Hi

I’m using client script in erpnext.

Thanks.

You may refer following code snippet:

frappe.ui.form.on("Material Request", "onload", function(frm, cdt, cdn){

    cur_frm.fields_dict["items"].grid.get_field("warehouse").get_query = function(doc) {

        return {

            filters: {

                'company': doc.company,

                'is_group': 0

            }

        }

    }
});
2 Likes

Hi @pioneerpathan

Thanks for the response, I tried with your code, there is no lucky, same result as my code.

Hello @ithelpdesk Can you send me a code snipet of yours ? I’m working on how to implement a child table in a parent table in script with the conditional statement.

Thank you, it’s working now. I’ve incorporated it at the parent level.

frappe.ui.form.on("School", "onload", function(frm) {
	frm.fields_dict["studnet_details2"].grid.get_field("subject").get_query = function(doc) {
        return {
            filters: {
                'subject_type': frm.doc.group,
            }
        }
	}
});
1 Like