frappe.ui.form.on('Service Request', {
// Trigger this function when you need to remove empty rows
delete_btn: function(frm, cdt, cdn) {
let row = locals[cdt][cdn];
// Check if the row is empty or contains invalid data
if (!row.item_code || row.qty === 0 || row.rate === 0) {
// Remove the row from the child table
frm.get_field(cdt).grid.grid_rows[cdn].remove();
// Optionally, refresh the form to reflect changes
frm.refresh_field(cdt);
}
}
});
It will be removed every time the page is first loaded.
Issue is, if the table has data, then it also removes the data. This logic is not right for the first row.