frappe.ui.form.on('Batch', {
expiry_date: function(frm, cdt, cdn){
var d = locals[cdt][cdn];
// put any logic here
var expires_in_days = frappe.datetime.get_day_diff(d.expiry_date, frappe.datetime.nowdate());
// update the field
frappe.model.set_value(cdt, cdn, 'expires_in_days', expires_in_days);
refresh_field("expires_in_days");
}
});
I created the above client script for Batch doctype to calculate the remaining days to expire in a custom field named “Expiry In Days” based on expiry date . The script works well when a new batch is created or when we manually re enters the expiry date of an existing batch.
What i want to achieve is that the script should update the custom field “Expiry In Days” automatically every day which it does not do. Then value of the custom field remains same as the value generated for the first time.
Appreciate if anyone can help in achieving my requirement.