Certain field must more than certain field if some "status" selected

Guys, I need your help.
I have a custom doctype that can make calculation. The Doctype has certain field that mandatory.
Which “status”, “total_need_to_pay” and “payment” are mandatory.

The status has 2 options:

  1. Outstanding
  2. Full Paid

The situation is here:
I want to make “total_need_to_pay” must more than “payment” if status is “Outstanding”.
If user input “total_need_to_pay” == “payment”, msgprint(“total need to pay must more that payment”)

I was try by myself by writing the code but have an error.

`TypeError: cur_frm.viewers is undefined[Learn More]`

And my code is:

frappe.ui.form.on('Employee Receipt', {
	validate: function(frm) {
		if (frm.doc.status == "Outstanding") {
			if (frm.doc.total_need_to_pay <= frm.doc.payment) {
				msgprint("total need to pay must more than payment");
				validate = false;
			}
		}
	}
}

Can anyone check my code please. I am very new in coding

I think this error is not related to this code can you share full screenshot of error as well as code

Thanks for your reply @hereabdulla

This is my full code:

frappe.ui.form.on('Employee Receipt', {
	validate: function(frm) {
		if (frm.doc.status == "Outstanding") {
			if (frm.doc.total_need_to_pay <= frm.doc.payment) {
				msgprint("total need to pay must more than payment");
				validate = false;
			}
		}
	}

	refresh: function(frm) {

	}
});

Error:

did u used any frappe.call?? if yes then share code

Okay i know where is the problem. It happens because I editing in custom script and .js file. So the code is become redundant. In the custom script has validate trigger and in .js file is also has. So that’s why its become error.

Thank you @hereabdulla for helping me.
I’m very appreciate your help.

:slight_smile:

Wait. but how to make it can not save if the total_need_to_pay is less than or equal to payment (wrong)?

Its okay
its already fixed.