Calculate (SUM) two fields and display the result on the third field on child table

Hi There,

I’m trying to create a script which calculates two fields (SUM) and display the result on the third field. Here is the script:

frappe.ui.form.on(“Appraisal Template - Performance”, “p_rating”, function(frm) {
frm.set_value(“p_score1”, frm.doc.p_rating + frm.doc.p_weight);
frm.refresh_field(“p_score1”);
});

frappe.ui.form.on(“Appraisal Template - Performance”, “p_weight”, function(frm) {
frm.set_value(“p_score1”, frm.doc.p_rating + frm.doc.p_weight);
frm.refresh_field(“p_score1”);
});

It always prompts “Field not found”. I’m sure that field p_score1 is the correct field name of field 3.


Hoping somebody could shed some light here.

Hi @NinYo,

Please apply it.

frappe.ui.form.on("Appraisal Template - Performance", {
    p_rating: function(frm,cdt,cdn) {
        var d = locals[cdt][cdn];
        frappe.model.set_value(cdt, cdn, 'p_score1', (d.p_rating + d.p_weight));
    }
});

// Syntax
frappe.ui.form.on("Child Table Name", {
    field_name_for_trigger_to_value_calculate: function(frm,cdt,cdn) {
        var d = locals[cdt][cdn];
        frappe.model.set_value(cdt, cdn, 'child_table_total_value', (d.child_table_value1 + d.child_table_value2));
       // frm.refresh_field('child_table_name');
    }
});

Thanks.

9 Likes

Thanks, @NCP. I’ll try this and get back to you.

This works