Child table value Duplication

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?

	validate: function(frm,cdt,cdn) {
		
		
		var a = [];
		$.each(frm.doc.table_2, function(index, source_row){

	
			globalThis.add_child = frm.add_child("neww");
			globalThis.Blockno = "";
			if(source_row.check_6 == true){
				a.push(source_row.q_block_no + ",");
				
			}
			a.forEach(hello);
			function hello(va){
				Blockno += va  
			
			}

		})
		add_child.q_block_no = Blockno;

	},

Hi @VINOTH,

Please check it.

Maybe it’s helpful for you.

Thank You!

1 Like

Hi, @NCP
Nope this is not working in my case :frowning_face:
Could you help me out in my case please :raised_hand_with_fingers_splayed:.

Thank you.

Hi @VINOTH,

Please try it.

frappe.ui.form.on('Child Table Name', {
    duplicate_field_name: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        $.each(frm.doc.table_name, function(i, row) {
            if (row.duplicate_field_name === d.duplicate_field_name && row.name != d.name) {
               frappe.msgprint('You added already exists on the table.');
               frappe.model.remove_from_locals(cdt, cdn);
               frm.refresh_field('table_name');
               return false;
            }
        });
    }
});

Thank You!

2 Likes

I haven’t idea about your scenario.
I just share the code to stop duplication. so apply the code according to your requirement.

Thank You!

Okay.

Thank you.