All questions

How do I fetch records from Zoho CRM in Deluge and handle an empty result?

I search Deals by stage and then loop over the response. The function fails when nothing matches.

Flow from searchRecords to an empty check to a for each loop in Zoho Deluge

Answer

`zoho.crm.searchRecords` returns a list. When no record matches, the list is empty, so check it before you loop or read fields. 1. Build the criteria string as `(Field:operator:value)`. 2. Call `searchRecords` with the module, criteria, page and page size. 3. Return early with `isEmpty()`. 4. Wrap nullable fields in `ifnull()` before converting them. Page size is capped at 200 records per call, so loop over pages for larger sets.

Zoho Deluge solution

// Sum the amount of all Closed Won deals (Zoho Deluge)
criteria = "(Stage:equals:Closed Won)";
response = zoho.crm.searchRecords("Deals", criteria, 1, 200);

if(response.isEmpty())
{
	info "No matching deals found";
	return;
}

total = 0;
for each deal in response
{
	total = total + ifnull(deal.get("Amount"), 0).toDecimal();
}
info "Closed Won total: " + total;

Edited by Jack · joysait@rediffmail.com

Add a Q&A

Drop an image here or click to choose. It is saved as images/N.ext.

Live preview

Publish to GitHub

Drafts 0

Drafts live in this browser only. Download or push them to make them public.

    Files to commit

    data/qa.json
    sitemap.xml
    robots.txt

    Push with the GitHub API

    Uses a fine-grained token with Contents: Read and write on your repo. The token stays in this page's memory only: it is never saved or sent anywhere except api.github.com.