How to calculate balance

how to calculate balance ?
where balance= total - collected

frappe.ui.form.on(‘Customer’, {

validate: function(frm, cdt, cdn) {

var total = flt(frm.doc.total);
var collected = flt(frm.doc.collected_);

var b = total - collected;

frm.set_value(‘balance’, b);
frm.refresh_field(‘balance’);

}

})

THIS IS MY CODE BUT ITS NOT WORKING … ANY HELP???

It should works. Did you get any error on the console?

Try to copy this and paste it on your script (just changed quotation marks …)

frappe.ui.form.on("Customer", {

validate: function(frm, cdt, cdn) {

    var total = flt(frm.doc.total);
    var collected = flt(frm.doc.collected_);

    var b = total - collected;

    frm.set_value("balance", b);
    frm.refresh_field("balance");

    }

})

Anyway … note that “validate” just run the code when you save the form, not on field changes …
Hope this helps.

Still not working and no errors

Hi:

Show a screenshot with your code and the form running.
It’s not easy helping without a little more info.



Hi:

Seems your script is disabled …

Turn on “Enabled” check on Client Script …

Hope this helps.

1 Like

Thank you
this solved my issue