VINOTH
January 10, 2023, 5:25am
1
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;
},
NCP
January 10, 2023, 5:50am
2
Hi @VINOTH ,
Please check it.
@shuvro-baset You can achieve that through creating a Client Script on the Vehicle doctype form and the script should be on the child table doctype.
Assuming that:
Child table doctype: Vehicle Item
Child table fieldname in main doctype: vehicle_items
Child table field to check: vehicle_item
Then the code can be something like the following.
frappe.ui.form.on("Vehicle Item", {
vehicle_items_add: function(frm, cdt, cdn) {
$.each(locals[cdt][cdn].vehicle_items, function(…
Maybe it’s helpful for you.
Thank You!
1 Like
VINOTH
January 10, 2023, 5:57am
3
Hi, @NCP
Nope this is not working in my case
Could you help me out in my case please .
Thank you.
NCP
January 10, 2023, 6:00am
4
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
NCP
January 10, 2023, 6:49am
7
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!