We provide more phone support than we do email support. As a result, we do not collect many email addresses. Desk prevents duplicate contacts by checking email only. We need to check for duplicate phone numbers also.
A solution we found is the following function. However, we are already using a validation rule to format the phone number using regex. We are unable to create two validation rules for the same Phone field. We understand a single custom function is necessary to combine both validations.
Another solution is to create a NEW phone field and set it as UNIQUE but this creates other major issues like needing to move the current values to another new phone field. Also the new phone field is not actively visible in certain views like with the default phone field. Second, the default phone field is not able to set as unique so a custom function is required.
The custom function must first check format validation using the following regex "^\d{10}$". Second, the custom function checks the database for duplicate phone numbers and blocks the creation of the contact if a match is found.
Can someone please help to complete the function? Below was written for CRM but we need it to work in Desk.
- entityMap = crmAPIRequest.toMap().get("record");
- ph = entityMap.get("Phone");
- response = Map();
- search = zoho.crm.searchRecords("Contacts", "(Phone:equals:"+ph+")");
- if(search.size() = 0)
- {
- response.put('status','success');
- }
- else
- {
- response.put('status','error');
- response.put('message','Phone number already exists');
- }
- return response;