I also have this kind of problem and this is my query.
frappe.ui.form.on(‘Material Request’, {
onload: function(frm) {
// Fetch and set parent item groups in custom_item_groups field
frappe.call({
method: “frappe.client.get_list”,
args: {
doctype: “Item Group”,
filters: {
‘is_group’: 1,
‘parent_item_group’: null // Fetch top-level item groups
},
fields: [“name”]
},
callback: function(r) {
if (r.message) {
let parent_item_groups = r.message.map(item => item.name);
console.log(“Parent item groups fetched:”, parent_item_groups);
frm.set_df_property(‘custom_item_groups’, ‘options’, parent_item_groups.join(‘\n’));
frm.refresh_field(‘custom_item_groups’);
}
}
});
},
custom_item_groups: function(frm) {
console.log(“Custom item group selected:”, frm.doc.custom_item_groups);
apply_item_code_filter(frm);
}
});
function apply_item_code_filter(frm) {
let item_group_filter = frm.doc.custom_item_groups;
console.log(“Applying item code filter based on custom item group:”, item_group_filter);
if (item_group_filter) {
// Fetch and filter items based on the selected parent item group
frappe.call({
method: "frappe.client.get_list",
args: {
doctype: "Item",
filters: {
'item_group': item_group_filter
},
fields: ["item_code", "item_name"]
},
callback: function(r) {
if (r.message) {
let filtered_items = r.message;
console.log("Filtered items fetched:", filtered_items);
// Clear the existing items table
frm.clear_table('items');
// Add the filtered items to the items table
filtered_items.forEach(item => {
let child = frm.add_child('items');
child.item_code = item.item_code;
child.item_name = item.item_name;
});
frm.refresh_field('items');
} else {
// If no items found, clear the items table
frm.clear_table('items');
frm.refresh_field('items');
}
}
});
} else {
// If no custom item group is selected, clear the items table
frm.clear_table('items');
frm.refresh_field('items');
}
}
I have a field called Item Group all item groups should be displayed in this field. But when I click food for example. The items in the table did not filter. Can you help me with this because I’m stuck in here. Thanks