How to fetch values from one child table under one doctype to another child table under another doctype

Hi All,

I want to fetch values from one child table under one doctype to another child table under another doctype
eg. The product bundle is a doctype and consists of a List of items in a child table.
So, I want to fetch items of product bundle doctype, to another Doctype which is Stock Entry as a child table in a single click of a button.

Appreciate a speedy response to my enquiry.

Thanks in advance!

Please help i m stuck from last 3 days

1 Like
frappe.ui.form.on("Batch Manufacturing Record", {
    bom_reference_number: function(frm, cdt, cdn) {
        frm.doc.list_of_ingredient = []
        frappe.call({
            method: "frappe.client.get",
            args: {
                name: frm.doc.bom_reference_number,
                doctype: "BOM"
            },
            callback(r) {
                if (r.message) {
                    for (var row in r.message.items) {

                        var child = frm.add_child("list_of_ingredient");

                        frappe.model.set_value(child.doctype, child.name, "material_code", r.message.items[row].item_code);
                        frappe.model.set_value(child.doctype, child.name, "material_name", r.message.items[row].item_name);
                        frappe.model.set_value(child.doctype, child.name, "proportion", r.message.items[row].proportion);
                        frappe.model.set_value(child.doctype, child.name, "quantity_required_per_standard_batch_size", r.message.items[row].qty);
                        frappe.model.set_value(child.doctype, child.name, "material_code_for_manufacturing_site", r.message.items[row].item_code_of_mfg_site);
                        refresh_field("list_of_ingredient");
                    }

                }
            }

        })


    }
})

Here I fetched BOM Items in My custom doctype Batch Manufacturing Record’s Child Table named list of Ingredients.

Thanks for your reply.
I am very new to erpnext so can you please explain me how to do with stock entry and product bundle and show all the items in stock entry child table which is already present
please help me out
Thanks

frappe.ui.form.on(“Stock Entry”, “get_bundle_items” {
new_item_code: function(frm, cdt, cdn) {
frm.doc.list_of_items = []
frappe.call({
method: “frappe.client.get”,
args: {
name: frm.doc.new_item_code,
doctype: “Product Bundle”
},
callback(r) {
if (r.message) {
for (var row in r.message.items) {

                    var child = frm.add_child("list_of_items");

                    frappe.model.set_value(child.doctype, child.name, "item_code", r.message.items[row].item_code);
                    frappe.model.set_value(child.doctype, child.name, "qty", r.message.items[row].qty);
                    refresh_field("list_of_items");
                }

            }
        }
    });
}

});

https://erpnext.org/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples

You should refer this.

@vivek22793

what is target doctype and mention the fields of the table and the names of source fields and target fields