Setting Email ID as Unique

Hi There,

Anyone there knows the solution for the below?

We have set Email Address as unique for the following Doctypes(after removing duplicate email ids):

· Lead

· Address

· Contact

We have Added Lead “123”, with email address 123@testV8.com, from that lead, created customer “123” and it automatically created also the contact with the same email 123@testV8.com. Added the same email id in the address of customer “123”.

If email was set as unique, it should not be accepted when saving email ID for address of customer “123” and email address on Lead “123” should be automatically removed and transferred to contact of customer “123”.

In this case, when we tried updating our system, we are getting the following error:

“email_id field cannot be set as unique in tabLead, as there are non-unique existing values”

OR

“email_id field cannot be set as unique in tabAddress, as there are non-unique existing values”

OR

“email_id field cannot be set as unique in tabcontact, as there are non-unique existing values”

USE CASE for SETTING EMAIL ADDRESS as UNIQUE : In actual scenario, USERS of ERPNext when adding new lead/customer in system tend to forget to check if it is already existing in the System. If email address will be set as
unique, at least, when user created new Lead with same email, the system will not allow to add it again, especially if it is already in the contacts of customer.

Thank you…

I believe that is not a system wide uniqueness, but a document type level of uniqueness. E.g. you can’t use the same email on more than one lead, or more than one address, etc. However you can have unique email across document types.

hi @James_Robertson, thanks for the response…

actually we have added customized field for Lead and contacts for Email Id2…
we cannot set it as unique because of this same error:

“email_id2 field cannot be set as unique in tabLead, as there are non-unique existing values”
“email_id2 field cannot be set as unique in tabContact, as there are non-unique existing values”

What we have done is we remove datas on this field and deleted the field in order to set email address as unique.

But the same error is showing upon making email address as unique.
and this error continue to show upon updating erp.

Do you know any solution on this?
Thanks…

A null value is still considered a value from a database perspective. So if the table/column is set to be unique do you also have it set to be mandatory? Even when you delete the field from the customize form area, the column in the table is still there. (I would prefer that erp nuke it, but alas it does not). Depending on how many records you have for leads and contacts, you could re-add the fields as they were, which will restore the data in them on the form.Then go through the records and add a dummy, but unique email address e.g. 1@example.com, 2@example.com, etc. to the fields and save. That should eventually clear the errors.

Hope this helps.

hi @James_Robertson, did you post any github issue on this?
It is very important to solve this issue in order to limit duplicate email addresses on different doctypes…
Especially, in actual scenario, there is not only one user who is adding leads and contacts in the system.

No, you can at any time. The issues database is wide open. I would suggest that email id uniqueness is an issue to you, but not everyone (including me) so I would make that be an option flag of some kind in the global settings.