Calculate some fields of child table and get some of those in parent doctype

Hi all. I want to calculate only some fields from table table and get that fields count in parent doctype. I have Table name tiffin details in which i want to calculate no of tiffin of roti, dal and rice in one field called total meal type 1 and rest in the second field called total meal type 2(salad, achar,sabji).
Please help.

Hi @SonalD,

Please try it.

frappe.ui.form.on('Delivery Note',  {
    validate: function(frm) {
        var ttl_itms_dicnt = 0;
        var ttl_itms_dicnt1 = 0;
        $.each(frm.doc.tifin_details,  function(i,  d) {
            if (d.type == "Roti" && d.type == "Dal" && d.type == "Rice") {
                ttl_itms_dicnt += flt(d.no_of_tiffin);
            } else if (d.type == "Salad" && d.type == "Achar" && d.type == "Sabji") {
                ttl_itms_dicnt1 += flt(d.no_of_tiffin);
            }
        });
        frm.doc.total_meal_type_1 = ttl_itms_dicnt;
        frm.doc.total_meal_type_2 = ttl_itms_dicnt1;
    } 
});

Please set the field name and table name according.

Maybe it works for you!

Thank You!