Dear Community,
when add Item if its already Exists means it need warning right under the field, like “Item Name already exists,please choose another name”.
Like Salary Structure works
I made the code but it not work as well
// Add this in Client Script section for Item DocType
frappe.ui.form.on('Item', { // Change to 'Customer' or 'Supplier' for those doctypes
refresh: function(frm) {
// Add keyup event listener for instant validation
$(frm.fields_dict.item_name.input).on('keyup', function() {
var item_name = frm.doc.item_name;
if (!item_name) {
frm.set_df_property('item_name', 'description', '');
return;
}
frappe.call({
method: 'frappe.client.get_list',
args: {
doctype: frm.doc.doctype,
filters: {
'item_name': item_name,
'name': ['!=', frm.doc.name || '']
},
fields: ['item_name']
},
callback: function(response) {
if (response.message && response.message.length > 0) {
// Show validation message under the field
frm.set_df_property('item_name', 'description',
`${item_name} already exists. Select another name`);
} else {
// Clear the message
frm.set_df_property('item_name', 'description', '');
}
}
});
});
}
});
This code am facing like it auto clear the field and popup comes only when we add multiple time in same field.
Kindly help to solve this issue.
Thanks in Advance,