Created
January 23, 2025 17:57
-
-
Save jaoltr/13c728b7ff2adc722f2763844a7f03fb to your computer and use it in GitHub Desktop.
Zoho Flow Deluge Custom Function - Fetch Contact by Phone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map fetchCRMcontactByPhone(string phoneNumber) | |
{ | |
// Initialize the return map with default values | |
resultMap = Map(); | |
resultMap.put("found",0); | |
resultMap.put("Contact_ID",""); | |
resultMap.put("First_Name",""); | |
resultMap.put("Last_Name",""); | |
resultMap.put("Mailing_Street",""); | |
resultMap.put("Mailing_City",""); | |
resultMap.put("Mailing_State",""); | |
resultMap.put("Mailing_Zip",""); | |
resultMap.put("Email",""); | |
resultMap.put("Account_Name",""); | |
resultMap.put("Account_ID",""); | |
// Check if phoneNumber has at least 10 characters | |
if(phoneNumber.length() < 10) | |
{ | |
// Phone number is too short; return the default map | |
return resultMap; | |
} | |
else | |
{ | |
// Take the rightmost 10 characters of the phone number | |
queryPhone = phoneNumber.right(10); | |
info queryPhone; | |
// Construct the COQL query | |
coqlQuery = "select id, First_Name, Last_Name, Mailing_Street, Mailing_City, Mailing_State, Mailing_Zip, Email, Account_Name from Contacts where ((Phone like '%" + queryPhone + "') or (Mobile like '%" + queryPhone + "')) limit 1"; | |
params = Map(); | |
params.put("select_query",coqlQuery); | |
// Execute the COQL query using InvokeUrl | |
response = invokeurl | |
[ | |
url :"https://www.zohoapis.com/crm/v7/coql" | |
type :POST | |
parameters:params.toString() | |
connection:"zoho_crm" | |
]; | |
info response; | |
// Check if the response contains data | |
if(response.get("data") != null && response.get("data").size() > 0) | |
{ | |
// Retrieve the first (and only) record | |
record = response.get("data").get(0); | |
// Populate the result map with retrieved data | |
resultMap.put("found",1); | |
resultMap.put("Contact_ID",record.get("id")); | |
resultMap.put("First_Name",record.get("First_Name")); | |
resultMap.put("Last_Name",record.get("Last_Name")); | |
resultMap.put("Mailing_Street",record.get("Mailing_Street")); | |
resultMap.put("Mailing_City",record.get("Mailing_City")); | |
resultMap.put("Mailing_State",record.get("Mailing_State")); | |
resultMap.put("Mailing_Zip",record.get("Mailing_Zip")); | |
resultMap.put("Email",record.get("Email")); | |
resultMap.put("Account_Name",record.get("Account_Name").get("name")); | |
resultMap.put("Account_ID",record.get("Account_Name").get("id")); | |
} | |
// Return the result map | |
return resultMap; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment