Fetch a child table

Seems the problem is right at the top.

frappe.ui.form.on("Payment Entry", {
    onload: function(frm) {
        frappe.model.with_doc("Sales Invoice Item", frm.doc.onload, function() {

        });
    }
});

NOT FOUND ERROR right at the top of the script. I must be doing something wrong,

not found

//The problem is right on initial funtion.

Is frm.doc.onload a valid trigger?

@Mahmoud_Ghoneem What is your doctype name and table name share more info to get help.

@adam26d your problem is

  1. frm.doc.onload is never going to work, because onload the Payment Entry has no idea where to get the details from.
  2. You cannot fetch from doctype ā€œSales Invoice Itemā€ because it is a Child Table, you should fetch from doctype ā€œSales Invoiceā€ where the Child table is nested.
  3. d = frm.add_child("Items") is wrong. You cannot have captial letters it should be
    d = frm.add_child("items") and you must have a field in Payment Entry which is called ā€œitemsā€ and is of the type ā€œTableā€ which in your case should have ā€œSales Invoice Itemā€ in de options section.
  4. $.each(tabletransfer.sales_invoice_item, function(index, row) should be $.each(tabletransfer.items, function(index, row) if you are going fetch from doctype ā€œSales Invoiceā€

Below I have edited all the points, now you need a field with type link to Sales Invoice in payment entry for your example I called the field ā€œsales_invoiceā€ where you fetch all the child tables, if you want it to be automatic, then you need to write a python script for that, donā€™t think JS can handle that.

//Including sales invoice items on the payment receipt.
frappe.ui.form.on("Payment Entry", "sales_invoice", function(frm) {
    frappe.model.with_doc("Sales Invoice", frm.doc.sales_invoice, function() {
        var tabletransfer= frappe.model.get_doc("Sales Invoice", frm.doc.sales_invoice)
        $.each(tabletransfer.items, function(index, row){
            d = frm.add_child("items");
            d.item_code = row.item_code;
            d.item_name = row.item_name;
            d.description = row.description;
            d.uom = row.uom;
            d.stock_qty = row.stock_qty;
            d.item_name = row.item_name;
            d.rate = row.rate;
            d.amount = row.amount;
            frm.refresh_field("items");
        });
    })
});

Good luck

5 Likes

Wow Thank you so much for the feedback @mrmo, Iā€™ll give it a shot!

Hi Sagarvora,

i want to make multiple delivery notes into 1 sales invoice. I have using Get Items From button to pick delivery notes available to make into 1 sales invoice.

I have added custom field in delivery notes doctype and i want to fetch that value into custom child table that i have created in sales invoice.

Any idea?