Created
January 23, 2025 17:59
-
-
Save jaoltr/ea356e4c3c3da79d940e4d1feb4dbe47 to your computer and use it in GitHub Desktop.
Zoho Flow Deluge Custom Function Fetch CRM Lead 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 fetchCRMleadByPhone(string phoneNumber) | |
{ | |
// Initialize the return map with default values | |
resultMap = Map(); | |
resultMap.put("found",0); | |
resultMap.put("Lead_ID",""); | |
resultMap.put("First_Name",""); | |
resultMap.put("Last_Name",""); | |
resultMap.put("Street",""); | |
resultMap.put("City",""); | |
resultMap.put("State",""); | |
resultMap.put("Zip_Code",""); | |
resultMap.put("Email",""); | |
// 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, Street, City, State, Zip_Code, Email from Leads 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("Lead_ID",record.get("id")); | |
resultMap.put("First_Name",record.get("First_Name")); | |
resultMap.put("Last_Name",record.get("Last_Name")); | |
resultMap.put("Street",record.get("Street")); | |
resultMap.put("City",record.get("City")); | |
resultMap.put("State",record.get("State")); | |
resultMap.put("Zip_Code",record.get("Zip_Code")); | |
resultMap.put("Email",record.get("Email")); | |
} | |
// Return the result map | |
return resultMap; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment