How to search ZOHO CRM Contacts using Phone value?

How to search ZOHO CRM Contacts using Phone value?


Warning

The Error

When attempting to search for contacts by phone number in Zoho CRM, you might encounter errors with this script:

con = phn.toLong; 
contactdetails = zoho.crm.searchRecords("Contacts",("Phone:equals":con*")); 
info contactdetails;

Common Issues in This Script

  1. Missing ParenthesestoLong is a method that requires parentheses - toLong()
  2. Incorrect Query Format: The search criteria uses an invalid syntax with misplaced parentheses and quotes
  3. Improper Search Operator: Using equals with a wildcard pattern is contradictory


Idea

Optimized Solution

The correct script to search for contacts by phone number is:

con = phn.toLong(); 
contactdetails = zoho.crm.searchRecords("Contacts", "Phone:starts_with:" + con + "*"); 
info contactdetails;

Why This Works Better

  1. Proper Method CalltoLong() is correctly called with parentheses
  2. Correct Search Criteria Format: The search criteria is formatted as a string with proper concatenation
  3. Appropriate Operatorstarts_with is the right operator when using a wildcard pattern

Additional Optimization Tips

  • Consider adding error handling to manage cases where phn cannot be converted to a number:

    try {
        con = phn.toLong();
        contactdetails = zoho.crm.searchRecords("Contacts", "Phone:starts_with:" + con + "*");
        info contactdetails;
    }
    catch(e) {
        info "Invalid phone number format: " + e;
    }
    
  • For international phone numbers, consider removing common prefixes (like "+") before conversion:

    cleanPhone = phn.replaceAll("[^0-9]", "");
    con = cleanPhone.toLong();
    
  • For better performance with large datasets, be as specific as possible with your search criteria to reduce the result set size

This optimized approach ensures reliable contact searches while avoiding common syntax errors in your Deluge scripts.