Filter feild in child table according to another feild in the same child

Hello,

I am now in a child table, I want to make a filter depend on another field in the same child table so when I change Asset Class the Asset Major Class is changing according to its asset class parent.

this is my code, that filter Asset Class field

frappe.ui.form.on(“Material Request”, {
setup: function(frm) {
frm.set_query(“asset_class”, “items”, function() {
return {
filters: {
“category_type”: “Class Type”
}
}
})
}
});


This is my code that have trouble ,

frappe.ui.form.on(“Requested Item”, {
asset_class: function (frm) {
frm.set_query(“asset_major_class”, function () {
return {
filters: {
“class_type_name”: frm.doc.asset_class
}
};
});
}
});

@OmarJaber use this syntax for the filter function

frm.set_query("asset_class", "items", function(doc, cdt, cdn){
   var child = locals[cdt][cdn];
   return {
      filters: {
           "category_type": child.category_type
      }
   }
});
2 Likes

Thanks, it works :wink: