Users cannot add rows with the same item twice. If do, then show an error message and remove the row/item from row

@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(row) {
                if (row.vehicle_item === cdt.vehicle_item) {
                    frappe.msgprint({
                        title: __('Duplicated Item'),
                        indicator: 'red',
                        message: __('The item you added already exist in the table.')
                    });
                    frappe.model.delete_doc(cdt, cdn);
                    frm.refresh_field('vehicle_items');
                    return false;
                }
            });
        }
});
3 Likes