Item Table filteration using Item Group Field

Dear all please check the below code for item tab le filtration based on item group selection in material request . But the filter is not working

frappe.ui.form.on(‘Material Request’, {
validate: function(frm) {
var itemGroup = frm.doc.pr_item_group;
frm.fields_dict[‘items’].grid.get_field(‘item_code’).get_query = function(doc, cdt, cdn) {
return {
filters: {
‘item_group’: itemGroup
}
};
};
}
});

@KAMAL_DAS

Add some timeout

Hi,
to filtering in cdt I have faced about month ago.
IMHO there are 3 points:

  • the field in a new row in table
  • the field in form view of the row (edit)
  • and the field already clicked => the query was set

I use this combination for dynamical changing of the queries for all 3 points:

        //queries for new rows and form view   
        frm.set_query("item_code", "items", () => {
    		return {
                filters: {item_code: ['in',data.message]}
    		};
    	});

// for new queries in all ready clicked fields

    	let rows = frm.get_field("items").grid.grid_rows;  
    	rows.forEach((row) =>{

    	   let field = row.columns.item_code.field;
    	   if (field){                                     
        	   field.get_query = () => {
        	       return {
        	           filters: {item_code: ['in',data.message]}
        	       };
        	   };
    	   }
    	});

Jirka