Filter by “item_group” in child table “item”

I am trying to do some customisation in ERP Next Quotation Module,
Wherein Once the user select an Item Group only those items should be displayed which are under that Item group.

I have changed the Quotation Item doc type to Show Item group 1st and made it mandatory, and show in list view, grid view also i have umarked it as hidden and read only and then saved it.

In quoation item doctype I also have changed the Item code to be fetched from “item_group:item_code”

I have also added a custom script in quoation-item doc type as below
“frappe.ui.form.on(‘Quotation Item’, {
refresh(frm) {
cur_frm.add_fetch(‘item_group’,‘item’,‘item’);
}
})”

Now, When I select the item group, it still shows me all the items, not the items under that particular item group.

Any help on this will be highly appreciated.

You should try to apply custom script for child table, and you need to use filter and not fetch

solved via

frappe.ui.form.on("Quotation", "refresh", function(frm) {
frm.fields_dict['items'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
    var child = locals[cdt][cdn];
    //console.log(child);
    return {    
        filters:[
            ['Item', 'item_group', '=', child.item_groups]
        ]
    };
};

});

I am using ERPNext version 15, and I was not able to deselect the Read Only option of Item Group field in Quotation Item doctype. So I had to create a new field called Custom Item Group, and then showed that field in Item table in Quotation

Also, In the filters statement in your answer, it should be child.item_group instead of child.item_groups.

And since I made a custom field, I had to write child.custom_item_group. And it works now.

// Event Trigger: The script listens for the refresh event
frappe.ui.form.on(“Quotation”, “refresh”, function(frm) {

// Select the 'items' field, which is a child table of Quotation Doctype
frm.fields_dict['items'] 

// Get a reference to the grid component of this child table
.grid 

// Get the Item Code field from this grid
.get_field('item_code') 

// Modify the query for fetching data for the item code field
.get_query = function(doc, cdt, cdn) { 
    
    // Get the current row's document
    var item_row = locals[cdt][cdn];
    
    // return only those items whose group matches the custom item 
    return {    
        filters:[
            ['Item', 'item_group', '=', item_row.custom_item_group]
        ]
    };
};

});