Hi @Qasrawii986,
Here we share the syntax of fetch the custom doctype child data in sales invoice.
frappe.ui.form.on("Sales Invoice", {
refresh: function(frm, cdt, cdn) {
frm.add_custom_button(__("Get Custom Child Table Details"), function() {
frm.clear_table("items");
frappe.call({
method: "frappe.client.get",
args: {
name: frm.doc.custom_parent_doctype_id,
// please set you custom doctype id/name in name field
doctype: "Custom Parent DocType Name"
},
callback(r) {
if (r.message) {
for (var row in r.message.custom_doctype_child_table_fieldname) {
var child = frm.add_child("items");
var rmi = r.message.custom_doctype_child_table_fieldname[row];
frappe.model.set_value(child.doctype, child.name, "item_code", rmi.custom_child_table_fielname_of_item_code);
frappe.model.set_value(child.doctype, child.name, "item_name", rmi.custom_child_table_fielname_of_item_name);
frappe.model.set_value(child.doctype, child.name, "description", rmi.custom_child_table_fielname_of_description);
frappe.model.set_value(child.doctype, child.name, "qty", rmi.custom_child_table_fielname_of_qty);
frm.refresh_field("items");
}
}
}
});
});
}
});
Please set the doctype, field name, and child table field name according to.
Learn Custom script examples.
I hope this helps.
Thank You!