A collection of production-ready automation scripts for Zoho CRM. Copy them directly into your functions or open them in the workspace to customize.
Automatically distribute incoming leads evenly across your sales team using a round-robin algorithm stored in a custom module.
// Get the next user in line
userIndex = zoho.crm.getRecordById("Settings", 123456789).get("Current_Index");
users = {"user1@domain.com", "user2@domain.com", "user3@domain.com"};
// Assign lead
nextUser = users.get(userIndex);
zoho.crm.updateRecord("Leads", leadId, {"Owner": nextUser});
// Update index
newIndex = if(userIndex + 1 >= users.size(), 0, userIndex + 1);
zoho.crm.updateRecord("Settings", 123456789, {"Current_Index": newIndex});Convert a Lead automatically when a specific field matches criteria, creating an Account, Contact, and Deal.
// Convert Lead mapping
mapping = Map();
mapping.put("overwrite",true);
mapping.put("notify_lead_owner",true);
mapping.put("notify_new_entity_owner",true);
// Deal Details
dealMap = Map();
dealMap.put("Deal_Name", leadName + " Deal");
dealMap.put("Closing_Date", today.addDay(30));
dealMap.put("Stage", "Qualification");
dealMap.put("Amount", 5000);
mapping.put("Deals", dealMap);
// Execute Conversion
response = zoho.crm.convertLead(leadId, mapping);
info response;A CRM Validation Rule that prevents users from changing a Sales Order's status to 'Closed' unless there is at least one Invoice related to it. If no invoice is found, it blocks the save and displays a custom error message.
// Extract Sales Order ID and Status from the CRM API Request
entityMap = crmAPIRequest.toMap().get("record");
saleorderid = entityMap.get("id");
status = entityMap.get("Status");
response = Map();
// Fetch related Invoices for this Sales Order
invoices = zoho.crm.getRelatedRecords("Invoices", "Sales_Orders", saleorderid);
// Validation: Prevent closing the Sales Order if no Invoices exist
// Note: 'סגור' means 'Closed'
if(invoices.isNull() && status == "סגור")
{
response.put("status", "error");
response.put("message", "לא ניתן לסגור הזמנה ללא חשבונית קשורה"); // "Cannot close order without related invoice"
}
else
{
response.put("status", "success");
}
return response;