Hi, I need a help.
Am having a table with check box while Am selecting the box and save it the data need to be fetched to the below table but the data is getting stored again and again for every save. So, now how to stop this duplication of data in child table?
Please apply the server script.
DocType Event → Before Save
Scenario 1: If you want to set the warning then you can apply it.
items = doc.get("items")
item_codes = set()
for row in items:
if row.item_code in item_codes:
frappe.throw(f"Duplicate entry found: {row.item_code}")
item_codes.add(row.item_code)
Scenario 2: If you want to remove the duplicate row then you can apply it.
items = doc.get("items")
unique_items = []
item_codes = set()
for row in items:
if row.item_code not in item_codes:
item_codes.add(row.item_code)
unique_items.append(row)
doc.set("items", unique_items)
Please set the table name and field name according to the scenario.