How to create Custom script to

How to create Custom script to fetch my customize table to sales invoice item
i mean , i create doc. and this doc contain a table witch have item , item name , rate , and amount
so how can i fetch them to sales invoice by click on specific button

also a script for this : hello guys , in Journal Entry Template i can add a routine Ledger so i add to the table in this doc. Branch,cost center , but when i select my Journal Entry Template it dosent fetch cost center and branch

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() {
                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,, "item_code", rmi.custom_child_table_fielname_of_item_code);
                            frappe.model.set_value(child.doctype,, "item_name", rmi.custom_child_table_fielname_of_item_name);
                            frappe.model.set_value(child.doctype,, "description", rmi.custom_child_table_fielname_of_description);
                            frappe.model.set_value(child.doctype,, "qty", rmi.custom_child_table_fielname_of_qty);

Please set the doctype, field name, and child table field name according to.

Learn Custom script examples.

I hope this helps.

Thank You!

1 Like

If you want to learn the Client script, then please attend the session on 14th June @ 2.30PM IST.

1 Like