Child Table | Continues rows are deleting when not used in another table

I have a child table called Meal Details. I want to delete rows which is not used in another table(not parent table) called capacity allocation.

What happens is, when I’m trying to delete row which is not falls in capacity allocation that should be deleted without fail. In my case when more then one meal is there continuously in row and after that those meals are there which is not falls in capacity allocation, then it is working fine…

But when some meals are there continuously in row which falls in Capacity Allocation & some meals are not falls after that again some meals are falls and when I delete rows then it is not deleting as expected.

frappe.ui.form.on(“Meal Details”, {
before_meal_details_remove: async function (frm, cdt, cdn) {
try {
const result = await new Promise((resolve, reject) => {
method: “frappe.client.get_list”,
args: {
doctype: “Capacity Allocation”,
filters: {
meal: cdn
callback: function (result) {
error: (err) => {
frappe.show_alert(“Something went wrong please try again”);
if (result.message && result.message.length > 0) {
const matchingRow = frm.doc.meal_details.find(row => === cdn);

			if (matchingRow) {
				frappe.throw("Capacity Allocation is done against meal " + matchingRow.meal + ", deletion is not permitted.");
	} catch (error) {
		frappe.throw(error)// Display error message if the Promise rejects
	return false;


Actual result:

  1. If Extra Tea & Dinner is not used in Capacity allocation table & I try to delete all then I am getting result as Breakfast, Lunch, Dinner. Ideally I should get output as Breakfast, Lunch, Evening Tea.
  2. If I have input as Breakfast, Lunch, Dinner, Evening Tea & I try to delete then I am getting correct output → Breakfast, Lunch, Evening Tea.

Expected Result:
When more than 1 continuous rows come to delete which is not included in another table then it should delete else it should not delete.