Count record in child table

image
count only the YES in child table

Parent doctype is Parent Data
child table doctype is FAMILY
display to data field: dependent_yes
result must be 1

1 Like

for server side:

def validate(self):
     dependent_yes = sum([1 for row in self.family if row.dependent_yes == "Yes"])

if dependent_yes != 1:
    frappe.throw(_("YOUR ERROR MESSAGE HERE"))

for client side

validate(frm) {
    const family = frm.doc.family;

    const dependent_yes_count = family.reduce((count, row) => {
        return count + (row.dependent_yes === "Yes" ? 1 : 0);
    }, 0);

    if (dependent_yes_count !== 1) {
        frappe.throw(__("YOUR ERROR MESSAGE HERE"));
    }
},
1 Like

solution:

1 Like