Fetch item table in sales invoice from custom doctype

hello everyone , can you please help me with client script to fetch feilds value from custom doctype to sales invoice items

Follow this guide

1 Like

@niha ,thank you,
but he added function to api python file , so can i do it without create method , or there is any api that fetch all records from another doctype

We have done the same for one of our clients.
We have created custom doc Inquiry and then based on the details filled in the Inquiry, Sales order is being created.

below is the custom script for both

In Inquiry

frappe.ui.form.on("Inquiry", {
"refresh": function(frm, cdt, cdn) {
    var d = locals[cdt][cdn];
        frm.add_custom_button(__("Create Sales Order"), function() {
            frappe.new_doc('Sales Order', {
                "customer": cur_frm.doc.company_name,
                "inquiry_no": cur_frm.doc.name
            });
        });
    }
});

And in Sales Order

frappe.ui.form.on("Sales Order", {
    "refresh": function(frm, cdt, cdn) {
        if(frm.doc.__islocal && frm.doc.inquiry_no){
            frappe.model.with_doc("Inquiry", frm.doc.inquiry_no, function() {
                var mcd = frappe.model.get_doc("Inquiry", frm.doc.inquiry_no);
                cur_frm.clear_table("items");
                    $.each(mcd.items, function(i, d) {
                        i = frm.add_child("items");
                        i.item_code = d.item_code;
                        i.item_name = d.item_name;
                        i.product_make = d.product_make;
                        i.cas_no = d.cas_no;
                        i.uom = d.uom;
                        i.stock_uom = d.uom;
                        i.description = d.description;
                        i.qty = d.qty;
                    });
                cur_frm.refresh_field("items");
            });
        }
    }
});

i need same thing but in my like Inquiry doctype i havent item table but some feilds i want to gather in sales invoice,

another question please , can this var mcd be a list of records ?