Duplicate Name Warning Message Need under Field

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
image

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,

Because it’s a default functionality. If the naming rule “Set by user” then will show the Salary Structure

Thanks for your response, then how can we set Naming series like CUS.-.YY.-.###?

Reference:

And already shown in the item without the code:

1 Like

it also need for Item Doctype, here am using item_code like ITM-001 etc, if i replace with set by user how can i made that as series no?

Once again thanks for your help.