Sales Order Item Table-Item group based item selection

Hello,

I have created a custom field in Sales Order Item table as below:

Custom Field Label: Item Category

Custom Field Data Type: Link

Custom Field Name: item_category

Options: Item Group.

My requirement is, when a particular item group is selected in the custom field item category, only related to that item group the items should display in the Item Code field.

I have tried it using this below script, but it’s not working.

frappe.ui.form.on(“Sales Order Item”, “refresh”, function(frm) {cur_frm.fields_dict[‘items’].grid.get_field(‘item_code’).get_query = function(doc) {
return {
filters: [[
‘Item’, ‘item_group’, ‘=’, doc.item_category
]]
}
};
});

Can anyone please help me with this?

Thanks & Regards,
Sujay

Try this :

cur_frm.set_query("item_code", "items", function(doc, cdt, cdn) {
    return {
        filters: {
            "item_group": cur_frm.doc.item_category
            }
        };
    });

Hi @youssef,

Thanks for the response.

I’ve tried this code, but still it’s not working.It is displaying all the items.

Check this: