Hi There,
On server, In leave_application.js file, there is existing custom script as below:
frappe.ui.form.on("Leave Application", {
....//code removed
employee: function(frm) {
frm.trigger("get_leave_balance");
},
leave_type: function(frm) {
frm.trigger("get_leave_balance");
},
from_date: function(frm) {
if (cint(frm.doc.half_day)==1) {
frm.set_value("to_date", frm.doc.from_date);
}
frm.trigger("calculate_total_days");
},
to_date: function(frm) {
if (cint(frm.doc.half_day)==1 && cstr(frm.doc.from_date) && frm.doc.from_date != frm.doc.to_date) {
msgprint(__("To Date should be same as From Date for Half Day leave"));
frm.set_value("to_date", frm.doc.from_date);
}
frm.trigger("calculate_total_days");
},
get_leave_balance: function(frm) {
if(frm.doc.docstatus==0 && frm.doc.employee && frm.doc.leave_type && frm.doc.from_date) {
return frappe.call({
method: "erpnext.hr.doctype.leave_application.leave_application.get_leave_balance_on",
args: {
employee: frm.doc.employee,
date: frm.doc.from_date,
leave_type: frm.doc.leave_type,
consider_all_leaves_in_the_allocation_period: true
},
callback: function(r) {
if (!r.exc && r.message) {
frm.set_value('leave_balance', r.message);
}
}
});
}
},
...
});
I have created a custom script on the client side. See below:
frappe.ui.form.on("Leave Application","get_leave_balance",function(frm) {
alert("Custom");
});
On Leave Application page, when I click on Employee or Leave Type, the browser displays “Custom” but when I click on Fron Date or To Date field, the browser doesn’t display “Custom” instead it calculates leave balance and displays it. Why doesn’t to call the custom method same as when I click on Employee or Leave Type field? Thanks.
MP