How to filter items by Item Group in sales Invoice

hello Everybody,
when creating new invoice
I need to make items filtered by the item group which the user selected in item Group ?
I tried this stuff but not working

    frappe.ui.form.on("Contracting Invoice","item_group", { function(frm) 
    {
        cur_frm.fields_dict['items'].grid.get_field('item_code').get_query = function(doc) {
             return {
                  filters:['Item', 'item_group', 'in', doc.item_group]
                 
    };console.log(cur_frm.doc.item_group)
};

}});

To be clear:
Have you added a link field item_groupto Sales Invoice?

1 Like

Yes I did

Try this, you’re missing a couple of brackets:
filters: [['Item', 'item_group', '=', doc.item_group]]

I don’t see any other difference from the script I use.

filter always empty whenever there are items in this group

I thought item_group was in parent doctype, not at same child table, that’s why the script you’re using doesn’t work. You have to look for a different script that work at child table level.