Sum two fields and fetch the data in a table

Hello just need a small help or a reference , i have two custom fields i want those fields to be divided and fetched in a child table how can i do this ?

If two custom field is in the parent doctype then check the simple syntax:

frappe.ui.form.on('Main Doctype', {
    field_a: function(frm) {
        calculate_and_fetch(frm);
    },
    field_b: function(frm) {
        calculate_and_fetch(frm);
    }
});

function calculate_and_fetch(frm) {
    if (frm.doc.field_a && frm.doc.field_b) {
        let result = frm.doc.field_a / frm.doc.field_b;

        frm.doc.child_table_field.forEach(row => {
            frappe.model.set_value(row.doctype, row.name, 'division_result', result);
        });

        frm.refresh_field('child_table_field');
    }
}

Now you have to set the doctype name, fieldname, child table name and child table fieldname in script.

1 Like

Hi, Thanks just another follow up question,

i want to fetch two three fields in the table, it is possible to do so right ?

possible!

1 Like