I have to field in chield table I need a script to calculate total days in third field
Could you please elaborate?
you have a field in the child table that you wish to update when modifying another field in this the same row?
Yes, exactly
Then you’ll need something like this:
frappe.ui.form.on('Project Task', {
date1: function(frm, cdt, cdn){
var d = locals[cdt][cdn];
if (!d.date1) return;
// put any logic here
var diff_day = d.date1 - d.date2
// update the field
frappe.model.set_value(cdt, cdn, 'end_date', diff_day);
}
});
So basically, when you’ll set the date1, the function will be triggered. you can access any information in that particular row using the variable ‘d’'.
Then you do the calculation you need to do and finally update the value in the row by using the frappe.model.set_value() for the field ‘end_date’.
I tried this script but not worked
frappe.ui.form.on('Plan Tasks', "refresh", function(frm, cdt, cdn){
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, 'total_days', frappe.datetime.get_day_diff( d.to_date, d.from_date));
refresh_field('total_days');
});
it won’t because the event is on ‘refresh’ instead of being on the field.
frappe.ui.form.on('Plan Tasks', {
to_date: function(frm, cdt, cdn){
var d = locals[cdt][cdn];
if (!d.to_date) return;
// put any logic here
var diff_day = frappe.datetime.get_day_diff(d.to_date, d.from_date);
// update the field
frappe.model.set_value(cdt, cdn, 'total_days', diff_day);
}
});
1 Like
Thanks, Its worked after Delete one of the brackets from ( d.to_date, d.from_date))
please edit so mark it as Solution
Meny Thanks