dealRecord = zoho.crm.getRecordById("Deals", deal_id);
velocityLoanCode = dealRecord.get("Velocity_Loan_Code");
if (velocityLoanCode == null || velocityLoanCode == "" || !velocityLoanCode.startsWith("VDMGL-")) {
return "Error: Please enter a valid Velocity Loan code. The Velocity Loan Code should start with VDMGL-";
} else {
apiKey = "My Api KEY - For Posting";
url = baseURL + "?apikey=" + apiKey + "&loancode=" + velocityLoanCode;
// Make HTTP GET request using Zoho CRM's getUrlContent function
responseString = zoho.crm.getUrlContent(url);
// Parse the JSON response
jsonResponse = json.parse(responseString);
deals = jsonResponse.get("deals");
if (deals.size() > 0) {
contactIds = List();
for each deal in deals {
borrowers = deal.get("borrowers");
for each borrower in borrowers {
mobile = borrower.get("cellPhone");
email = borrower.get("email");
contactSearchCriteria = "";
if (mobile != null) {
// Search for contact based on mobile number
contactSearchCriteria = "Mobile:equals:" + mobile;
} else if (email != null) {
// Search for contact based on email address
contactSearchCriteria = "Email:equals:" + email;
}
if (contactSearchCriteria != "") {
// Search for contact using searchRecords method
contacts = zoho.crm.searchRecords("Contacts", contactSearchCriteria);
if (contacts.size() > 0) {
contactId = contacts[0].get("id");
contactIds.add(contactId);
}
}
}
}
// Return the contact IDs
return contactIds.toString();
} else {
return "No deals found in the Velocity API response.";
}
}