Filter Child table base on parent field

How can I filter a child field base on parent field in javascript?

use case:

I have a parent field school section and when I click add new row in the child table there is a student field which should be filter base on the school section selected in the parent field.

any idea how to do this?

1 Like

after reading codes from erpnext :slight_smile: the best documentation to learn frappe :slight_smile: I have solve this by this code

frappe.ui.form.on("Grade Sheet", "section", function (frm) {
    cur_frm.set_query("student", "score", function (frm) {
        return {
            query: "wela.grading.doctype.student.student.get_student_list",
            "filters": {
                "section": cur_frm.doc.section
            }
        }
    });
});

the key here is cur_frm.set_query(“student”, “score”, function (frm)
“student” = child field
“score” = the name of the child field in the parent

Hope it will helps others.

16 Likes