We need help to validate custom fields data by client or server script.
Custom fields like Phone 1, Phone 2 and Phone 3 in Customer doctype.
Need validate like all 3 phones should not be duplicate.
e.g. >> customer 1 we added 12345 in phone 1
>> customer 2 if we add 12345 in phone 2, it should validate and give message like 12345 is already exists in phone 1 of customer 1.
We need to validate from database records if phone 1 = 123456 is already added in database and for new customer if we add phone 2 = 123456, it should check in database and show message.
def validate_phone_number(phone_number):
# Check if the phone number exists in the database for existing customers.
existing_customer = frappe.get_all("Customer", filters={"mobile_no": phone_number}, fields=["name"])
if existing_customer:
# Phone number already exists for a customer.
return _("Phone number {} is already associated with customer {}.").format(phone_number, existing_customer[0]["name"])
```
extend your logic and add it to before_save hook (Insert + update ) will be covered