Fetch a child table

What is your use case? If you need instant update across documents… wouldn’t you rather keep the additional fields as a part of the same document?

what i need is to copy the entire sales order item table from sales order doctype to my new doctype

SO, just to be clear, you want the functionality like “Get Items From”?

maybe or something like make which can make the sales order to invoice with all the details

In that case: see the code I linked above. Since you’re making your document from sales order, I gave as an example the function that executes in the backend when you make delivery note from sales order.

so will i need to repeat the with the new doctype ??

instead of delivery note ??

Yes, you need to write custom code in your custom app which will get executed when you click the button to get items. If you’re not comfortable with python you can get this done as paid development.

try this,

Customer: parent_table_name
items : child_table_name
x = frappe.get_doc(‘Customer’, ‘16gtrf3’).get(‘items’)

@Mahmoud_Ghoneem, I think you can also pull the items via Javascript using a series of frappe.client.get snippets but you’re going to need the name variable of the Document whose items you’re trying to fetch.

Can you also share the code you used to fetch the entire table from Sales Order so that we can see your approach to solving this one? Thanks! :slight_smile:

Hera

Is this server-side, what is 16gtrf3 in this case?

@Mahmoud_Ghoneem did you achieve this? Please share how.

not yet :frowning:

Please dont give up or withdraw it. Others will be working towards something similar. My being here is proof.

Here’s my script so far. Still trying to make it work. The fields are selectable in print preview but it isnt appearing at all. I suspect empty values.

//Including sales invoice items on the payment receipt.
frappe.ui.form.on("Payment Entry", onload, function(frm) {
    frappe.model.with_doc("Sales Invoice Item", frm.doc.onload, function() {
        var tabletransfer= frappe.model.get_doc("Sales Invoice Item", frm.doc.onload)
        $.each(qmtable.sales_invoice_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");
        });
    })
});
1 Like

replace qmtable with tabletransfer

Thanks, I also changed

sales_invoice_items

to

But still needs further troubleshooting.

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?