Custom script to get customer balance on Sales Invoice

Found the solution from here Cur_frm.add_fetch - #5 by PAMPERO

This will fetch the first’s row’s value. We can use this for any types of child table value fetching into a single field of another doctype.

frappe.ui.form.on("Sales Invoice", "customer",
function(frm) {
    frappe.call({
        "method": "frappe.client.get",
        args: {
            doctype: "Customer",
            name: frm.doc.customer
        },
        callback: function (data) {
            frappe.model.set_value(frm.doctype,
                frm.docname, "credit_limit",
             data.message.credit_limits[0].credit_limit
               );
        }
    });
});
1 Like