Wednesday, June 3, 2015

searchRecords with multiple criteria in Zoho CRM API


I discovered something really cool tucked away in the Zoho CRM forums today. For the history, check out this thread. In summary, the searchRecords API task in Zoho CRM is impossible to use if you have multiple criteria and in general it's pretty annoying to get the single criterion right. In the forum thread, Zoho Support advised that you can actually use getRecords with a view name. This feature is not documented on the getRecords page at all but I can confirm it works:D

This is really, really cool. It's going to make my life as a Zoho dev much easier! Instead of having to do something really inefficient and ugly like:
leadRecords = zoho.crm.searchRecords("Leads","(Created Time|<|" + yesterday_date +")",fromIndex,toIndex);
for each ele in leadRecords
{
lead_source = ele.get("Lead Source");
createTime=(ele.get("Created Time")).toDate();
info "Found lead with create time: " + createTime;
dayDiff=days360(createTime,yesterday_date);
if(dayDiff  <=  2 && lead_source == "ClientWebsite.com.au")

I can just create a view called 'ClientWebsite leads in last 3 days' with relevant criteria and do:
leadRecords = zoho.crm.getRecords("ClientWebsite leads in last 3 days"); 

If you've struggled with cludgey searchRecords tasks in the past, you're going to love this trick:D

1 comment: