Filter by "item_group" in child table "item" in quotation

in doctype quotation i have field or parent called item_group, in those item groups various items are categorized. please suggest the script for filtering items by their appropriate group.

for example as i attached if i selects consumable in item_group in parent
then in item table all the only items which comes under consumable should be added into table

1 Like

Try this,

cur_frm.cscript.onload = function(frm) {
         cur_frm.set_query("item_code", "items", function() {
            return {
                "filters": {
                    "item_group": frm.doc.item_group

@schilgod thanks
but the field is not only consumable there are other fields too.
so if I selects other group ex.product the item which comes under product group should be appeared.
group field should be generalized so that if any new one added it could work for it too.

See my updated answer

1 Like

isn’t working.
actually item_code is one of field of item…

Yes you will be able to add items only which belong to item_group selected.

Can you elaborate? You want the all items of the group to be added when item_group is selected or you want the user to be able to add only those items belonging to the selected item_group?

user won’t select item, user will select only item_group among ,then all the items should be added into list automatically of that particular group.

refer below,
you need to write a python function to get the items and in custom script add those items in the table

frappe.ui.form.on("Quotation", "item_group", function (frm, cdt, cdn) {{
        args: {
            item_group: frm.doc.item_group
        callback: function(r) {
            var items = [];
            for(var i=0; i< r.message.length; i++) {
                var d = frm.add_child("items");
                $.extend(d, r.message[i]);

which changes i will have to make?
or could you explain me please…!

updated my reply above.

refer the link to create custom python whitelist method to get the items for the selected item_group.

I am quite new here please elaborate the solution and the links you sent.
where to write python function and how

not working

do you have a custom app?

no i don’t have

Sorry it may not work with custom script only. I will check and let you know or may somebody will reply

so what should be done?

If you have custom app, you can write python method to get the items and call it from custom script to add items to the child table.

May be its possible to do it with custom script, I will try it and let you know.

You can search the forum as well to find if the item details can be retrieved with custom script only.

I did already but i didn’t get any solution in forum.
for temporary can we do it for any single item_group?
later will do something.

try let me know I;m also trying hard

@Dbone @Francisco_Buendia do you have any solution ?