Frappe.client.get_list not working for Child Table

Hi,

I am trying to fetch child table records from a Client Script.
I appreciate help on the following frappe.client.get_list call:

    frappe.call
    (
        {
            method: "frappe.client.get_list",
            args:
            {
                doctype  : 'Delivery Items',
                parent   : 'Delivery', 
                filters  : [ ['item', 'like', '%' ] ], 
                fields   : ["*"],
                order_by : 'item',
                limit_page_length: 0
            },
            callback: function (response) 
            {
                if (response.message) 
                {
                    $.each(response.message, function(i, row) 
                    {   child_add      = cur_frm.add_child(item_tbl_id);  
                        child_add.item = row.item ;
                        child_add.qty  = row.qty ;
                    });
                    frm.refreh_fields(item_tbl_id);
                }
            }
        }
    ) ;

Delivery Items is not a doctype, it’s a child table within the “Delivery” doctype. Use queries instead? or, access the child table through the document as in

frappe.client.get_doc,
    args: {
        doctype: "Delivery",
        name: "Delivery Document Name", 
    },
    callback: function(response)

Edit:
You have typos in refresh field.
Also use these instead;
frm.add_child(“item_tbl_id”) and
frappe.model.set_value

Hi @Yamen_Zakhour ,

These are CUSTOM doc types, not the standard document types.
Both “Delivery” and “Delivery Items” are our custom doc types. And we have a Custom form where we use this code logic.

Thanks,
Joseph

Hi,

It looks like some bug in Fetching Child Records by calling the standard API “frappe.client.get_list()”. It is fetching null records with null values for Child Table.

Solution :

We used custom API written in “Server Script” and calling that in the “Client Script”. This is working fine.

Client Script Code :

    frappe.call
    (
        {
            method: "custom_api_get_del_item_sum",
            args:
            {
                item : frm.doc.item
            },
            callback: function (response) 
            {
                    $.each(del_list, function(i, row) 
                    {   child_add      = cur_frm.add_child(item_tbl_id);  
                        child_add.item = row.item ;
                        child_add.qty  = row.qty ;
                    });
                    frm.refreh_fields(item_tbl_id);
            }
        }
    ) ;

Server Script : custom_api_get_del_item_sum

item = frappe.form_dict.item ;
doc_type   = "Delivery Items" ;
del_list   = frappe.db.get_all(doc_type, 
                    filters  = {'item'       : ['like', item+'%'],
                                 'docstatus' : '1'
                               }, 
                    fields   = ['item', 'SUM(del_qty) as del_qty'], 
                    group_by = 'item',
                    order_by = 'item'); 

frappe.response['result'] = del_list ;

Note : frappe.db.get_all() skips permissions. So there is no permission issue fetching child table records.

Hope this helps someone facing similar issue.

Thanks,
Joseph