string button.search_contacts_by_zip(String dealId)
{
dealLong = dealId.toLong();
dealRecord = zoho.crm.getRecordById("Deals",dealLong);
if(dealRecord == null)
{
return "No Deal found for ID: " + dealId;
}
dealZip = ifnull(dealRecord.get("Zip_Code"),"").trim();
if(dealZip == "")
{
return "No Zip on this Deal.";
}
// Attempt partial match using :like:
searchQuery = "(Zip_Codes:like:\"" + dealZip + "\")";
contactMatches = zoho.crm.searchRecords("Contacts",searchQuery);
info "contactMatches => " + contactMatches;
// Debug
if(contactMatches.isEmpty())
{
return "No contacts found with '" + dealZip + "' in Specific Areas.";
}
matchingIds = list();
for each c in contactMatches
{
cId = c.get("id");
// <--- must be "id" here
if(cId != null)
{
matchingIds.add(cId.toLong());
}
}
updateMap = Map();
updateMap.put("Matching_Buyers",matchingIds);
updateResp = zoho.crm.updateRecord("Deals",dealLong,updateMap);
return "Matched " + matchingIds.size() + " buyer(s) for " + dealZip + ".";
}