Restrict to add duplicate items in child table

how to avoid making duplicate entries from user in child table

Hi @asd ,
Can you explain a little more what you are trying to do?
Technically for custom doctype, you just have to change the name of the entry to make it unique.
For ERP, you can overwrite the auto-naming method.

This is possible by adding custom script that will be triggered when adding new item in the child table.


frappe.ui.form.on(‘Sales Invoice Item’, {
item_code: function(frm, cdt, cdn){
var item = locals[cdt][cdn];


Of course you need to have a for loop to check each item in the table if it is the same item_code, if yes, then you need to delete the current record (which is the item variable configured in the example as var item = locals[cdt][cdn]; ) and showing message for the user that duplicate items are not allowed to be added.


Thanks for the reply @bghayad
but can you please explain it some more with code

This need to be written using custom script (search for custom script from awesome bar) or it can be written in the .js file (so if you need to do this in sales invoice, then you need to add this code in sales_invoice.js file).

Please give a look for this link as reference for you:

And you can ask me on certain points, so it will be easier to explain.