How to compare values between two fields

Good morning guys.
please I need your assistance. I have Field A and Field B. I want to compare field A and field B. if field A is greater than field B, the message should show on the screen that “Field A can not be greater than field B” and the form should not be saved.
below is my code;
var field_A = frm.doc.field_a;
var field_B = frm.doc.field_b;

 if(field_A >  field_B){
    frappe.msgprint({
     title: __("Invalid Value"),
     indicator: "red",
     message: __("field Acan not be more than field B"),
   });

}else{
frm.set_value(“field_a”, total);
refresh_field(“paid_a”);
}

1 Like

Hi @lubem,

Please apply it.

frappe.ui.form.on('Your DocType',  {
    validate: function(frm) {
        var field_A = frm.doc.field_a;
        var field_B = frm.doc.field_b;
        if(field_A > field_B) {
            frappe.msgprint({
                 title: __("Invalid Value"),
                 indicator: "red",
                 message: __("Field A can not be greater than field B"),
               });
            validated = false;
        }
        else{
            frm.set_value("field_a", total);
            refresh_fields("field_a");
        }
    }
});

Then reload and check it, please.

Thank You!

Thanks For your great information.

thank you