Calculating Time Difference in Child Table

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(''), 'years');

To set value in child table we use
frappe.model.set_value(cdt, cdn, "fieldname",value);
Not cur_frm.set_value

1 Like