Deluge is Zoho's scripting language. In Zoho CRM you use it in custom functions, which run from workflow rules, Blueprints, buttons and schedules. These Zoho Deluge examples are short, real-world functions you can adapt.
Field and module API names differ between orgs: check yours in Setup > Developer Hub > APIs > API Names. Test every function in a sandbox first. In each example, the arguments (like leadId) are mapped from the record when you attach the function to a workflow.
Working with records
1. Update a field on the current record
// Argument: leadId (Leads > Lead Id)
zoho.crm.updateRecord("Leads", leadId, {"Rating":"Hot"});2. Copy a value from the account to a contact
// Argument: contactId
contact = zoho.crm.getRecordById("Contacts", contactId);
account = contact.get("Account_Name");
if(account != null)
{
acc = zoho.crm.getRecordById("Accounts", account.get("id"));
zoho.crm.updateRecord("Contacts", contactId, {"Industry_Copy":acc.get("Industry")});
}3. Create a follow-up task
// Argument: dealId
task = Map();
task.put("Subject", "Follow up on proposal");
task.put("Due_Date", zoho.currentdate.addDay(2).toString("yyyy-MM-dd"));
task.put("What_Id", dealId);
task.put("$se_module", "Deals");
zoho.crm.createRecord("Tasks", task);4. Add a note to a record
note = Map();
note.put("Note_Title", "Auto note");
note.put("Note_Content", "Lead came from the pricing page form.");
note.put("Parent_Id", leadId);
note.put("se_module", "Leads");
zoho.crm.createRecord("Notes", note);5. Find a duplicate by email
// Arguments: leadId, email
matches = zoho.crm.searchRecords("Contacts", "(Email:equals:" + email + ")");
if(matches.size() > 0)
{
zoho.crm.updateRecord("Leads", leadId, {"Existing_Contact":true});
}6. Sum related deals onto the account
// Argument: accountId
deals = zoho.crm.getRelatedRecords("Deals", "Accounts", accountId);
total = 0.0;
for each d in deals
{
if(d.get("Stage") == "Closed Won")
{
total = total + ifnull(d.get("Amount"), 0).toDecimal();
}
}
zoho.crm.updateRecord("Accounts", accountId, {"Lifetime_Value":total});Dates and text
7. Days since the last activity
lead = zoho.crm.getRecordById("Leads", leadId);
last = lead.get("Last_Activity_Time");
if(last != null)
{
days = daysBetween(last.toDate(), zoho.currentdate);
zoho.crm.updateRecord("Leads", leadId, {"Days_Idle":days});
}8. Clean a phone number
// Argument: leadId, phone
clean = phone.replaceAll("[^0-9+]", "");
zoho.crm.updateRecord("Leads", leadId, {"Phone":clean});9. Build a deal name from its parts
deal = zoho.crm.getRecordById("Deals", dealId);
name = deal.get("Account_Name").get("name") + " - " + deal.get("Type") + " - " + zoho.currentdate.toString("MMM yyyy");
zoho.crm.updateRecord("Deals", dealId, {"Deal_Name":name});Notifications
10. Email the owner's manager
sendmail
[
from :zoho.adminuserid
to :"sales-manager@yourcompany.com"
subject :"Large deal created"
message :"A deal over $20,000 was just created. Record id: " + dealId
]11. Post to a Slack channel
payload = {"text":"New hot lead: " + leadName};
response = invokeurl
[
url :"https://hooks.slack.com/services/XXX/YYY/ZZZ"
type :POST
parameters:payload.toString()
headers:{"Content-Type":"application/json"}
];
info response;Integrations
12. Call an external API with a connection
// "enrich_api" is a Connection set up in Setup > Developer Hub > Connections
response = invokeurl
[
url :"https://api.example.com/company?domain=" + domain
type :GET
connection:"enrich_api"
];
zoho.crm.updateRecord("Accounts", accountId, {"Employees":response.get("employees")});13. Create an invoice in Zoho Books from a won deal
orgId = "YOUR_BOOKS_ORG_ID";
invoice = Map();
invoice.put("customer_id", booksCustomerId);
lines = List();
lines.add({"name":dealName, "rate":amount, "quantity":1});
invoice.put("line_items", lines);
result = zoho.books.createRecord("Invoices", orgId, invoice, "books_connection");
info result;Validation and schedules
14. Block a save with a validation function
// Used as a validation rule function. crmAPIRequest carries the record.
record = crmAPIRequest.toMap().get("record");
response = Map();
if(record.get("Discount") != null && record.get("Discount").toDecimal() > 20)
{
response.put("status", "error");
response.put("message", "Discounts above 20% need manager approval.");
}
else
{
response.put("status", "success");
}
return response;15. A scheduled clean-up of stale deals
// Run daily from Setup > Automation > Schedules
deals = zoho.crm.searchRecords("Deals", "(Stage:equals:Proposal)");
for each d in deals
{
modified = d.get("Modified_Time").toDate();
if(daysBetween(modified, zoho.currentdate) > 14)
{
zoho.crm.updateRecord("Deals", d.get("id"), {"Stale":true});
}
}Tips
- Use info statements while testing; they print to the function's log.
- searchRecords returns a page of results (200 by default). Page through for more.
- Function calls count against your org's daily limits, so avoid functions that call each other in loops.
- Store secrets in Connections, never in the code.
Need functions written for your org? See our Zoho CRM development service.
FAQ
What is Deluge in Zoho?
Zoho's scripting language, used for custom functions in Zoho CRM, Creator, Books and other Zoho apps.
Where do I write Deluge in Zoho CRM?
In Setup > Developer Hub > Functions, or directly from a workflow rule, Blueprint transition, button or schedule.
Can Deluge call external APIs?
Yes, with invokeurl. Use a Connection for authentication.
Are there limits on Deluge functions?
Yes. Execution time and daily call limits depend on your edition.