Insert unique record each row in child table. but below code it just duplicating all the values whenever the Insert button is clicked

var current_user = frappe.session.user;
frappe.ui.form.on(“Milk Entry”,{
verify: function(frm) {
frappe.call({
method: “frappe.client.get”,
args: {
doctype: “User”,
filters: {“email”:current_user} //user is current user here
},
callback: function® {
frappe.model.add_child(cur_frm.doc,“Milk Entry List”,“milk_list”);
$.each(frm.doc.milk_list || [], function(i, v) {
frappe.model.set_value(v.doctype, v.name, “code”,cur_frm.doc.member)
frappe.model.set_value(v.doctype, v.name, “milk_type”,cur_frm.doc.milk_type)
frappe.model.set_value(v.doctype, v.name, “volume”,cur_frm.doc.volume)

			})
			frm.refresh_field('milk_list');
		    cur_frm.set_value("member",r.message["member"]);
	        cur_frm.set_value("milk_type",r.message["milk_type"]);
	        cur_frm.set_value("volume",r.message["volume"]);
		}
	})
}

})

any solution?

Well the problem is you’re not checking what is in the child table before appending something. First check if the milk list already has what you’re about to set it to. In the callback function.

Or use the form events that triggers when the child table changes to check for duplicates documentation