I wanted to calculate the total experience for Employee External Work History (child table) in Employee (doctype). As shown below, the ‘Experience’ field should be calculated in years based on the ‘From’ and ‘To’ fields.
Here is my code which doesn’t work
frappe.ui.form.on('Employee External Work History', { setup: function(frm, cdt, cdn) { set_experience(frm, cdt, cdn); } }); var set_experience = function(frm, cdt, cdn) { var experience = 0.0; $.each(frm.doc.external_work_history, function(i, row) { cur_frm.set_value(cdt, cdn, 'row.experience', moment('row.from').diff('row.to'), 'years'); cur_frm.refresh_field('experience'); }); };