Skip to content

Blog · Zoho Deluge · Code examples

Zoho Deluge scripts: 10 ready-to-use examples

Zoho Deluge scripts are short programs, written in Zoho’s own scripting language, that do the jobs point-and-click automation cannot: totals across records, duplicate checks, invoices built from deals, calls to other systems. Below are 10 Deluge script examples for Zoho CRM, Zoho Books and Zoho Creator. Each one says where it runs, explains the lines that matter, and lists what to change before you paste it in.

Written by our Zoho developersAbout 16 minutes to read

Three of the ten scriptsSample code

Zoho CRM · Workflow rule

Roll up open pipeline

Account shows its open pipeline

Zoho Books · From a CRM deal

Draft the invoice

Draft invoice waits for review

Zoho Creator · On validate

Block a double booking

Form refuses the overlap

What is Zoho Deluge?

Deluge is the scripting language built into Zoho’s apps. You write it in an editor inside the app, it runs on Zoho’s servers, and it can read and change records in Zoho CRM, Zoho Books, Zoho Creator and other Zoho apps, or call outside systems over HTTP.

The name is short for Data Enriched Language for the Universal Grid Environment, which nobody says out loud. What matters is that it was designed for business data, not general programming. You do not declare types, you do not manage servers, and most of the work is done by built-in tasks such as zoho.crm.getRecordById or zoho.books.createRecord. If you have written a spreadsheet formula or a little JavaScript, the syntax will look familiar within an hour.

That simplicity is also the trap. A Deluge script is still code. It can loop through thousands of records, use up your daily call allowance, or set off other automations. The examples below are written to be safe starting points, with the risky lines called out.

Where do Deluge scripts run in Zoho?

In Zoho CRM they run as functions called from workflow rules, Blueprint transitions, buttons, schedules or other functions. In Zoho Creator they run in form and report workflows. Zoho Books, Zoho Desk, Zoho Flow and several other apps have their own custom function screens.

  • Zoho CRM functions. The most common home for Deluge. A function takes arguments, such as the ID of the deal that fired a workflow rule, and does the work. Button functions return a message the user sees on screen.
  • Zoho CRM schedules. A function that runs at a set time or on repeat, with no record to start it, for example a nightly check for stale deals.
  • Zoho Creator workflows. Scripts tied to form events such as On Validate, On Success, On User Input and On Load, plus scheduled and report workflows. Creator apps are mostly Deluge underneath.
  • Zoho Books and other apps. Custom functions triggered by Books workflow rules, custom buttons and schedules. Zoho Flow can also run a Deluge step inside a no-code flow.

The language is the same everywhere, but the built-in variables change. In Creator you read the current form with input.Field_Name; in a CRM function you get an ID as an argument and fetch the record yourself. Keep that in mind when you move a script from one app to another.

Deluge basics you need before the examples

Five things cover almost every script: variables, maps (key and value pairs, which is how records arrive), lists, the for each loop with if conditions, and info for printing values while you test.

Deluge basics · sample
// A map holds field names and values, just like a record
lead = Map();
lead.put("Last_Name", "Rivera");
lead.put("Lead_Source", "Web Form");

// A list holds several values
states = List();
states.add("CA");
states.add("TX");

// Loop and decide
for each s in states
{
	if(s == "CA")
	{
		info "West team";
	}
	else
	{
		info "Central team";
	}
}

// Read a value back, with a fallback when it is empty
source = ifnull(lead.get("Lead_Source"), "Unknown");

Two habits save hours. Use ifnull() whenever a field might be empty, because a missing value breaks math and text joins. And use info generously while testing: everything it prints shows in the output panel when you click Save and Execute, so you can see what the script actually received.

01The script library

10 Deluge script examples you can adapt

Filter by app or by what starts the script. Tap a highlighted line in any script to read what it does. Field names such as Open_Pipeline are samples: swap in the API names from your own account before you run anything.

App
Runs from

Showing all 10 scripts.

1

Roll up open pipeline onto the account

Zoho CRMWorkflow rule on DealsArgument: dealId

Sales managers want to see, on the account itself, how much is still open across every deal. Zoho CRM has rollup summary fields in some editions, but a script gives you full control over which stages count. Run it from a workflow rule on Deals when a deal is created or its amount or stage changes.

Deluge · Zoho CRM function
// Argument: dealId (map it to Deals > Deal Id)
deal = zoho.crm.getRecordById("Deals", dealId);
account = deal.get("Account_Name");
if(account == null)
{
	return;
}
accountId = account.get("id");
deals = zoho.crm.getRelatedRecords("Deals", "Accounts", accountId);
total = 0.0;
for each d in deals
{
	stage = d.get("Stage");
	if(stage != "Closed Won" && stage != "Closed Lost")
	{
		total = total + ifnull(d.get("Amount"), 0).toDecimal();
	}
}
update = Map();
update.put("Open_Pipeline", total);
zoho.crm.updateRecord("Accounts", accountId, update);
  1. Line 3 A lookup field arrives as a small map with the related record’s name and ID, not as plain text.
  2. Line 9 Fetches every deal linked to the account. Related records come back in pages of up to 200, so very large accounts need a page loop.
  3. Line 14 Change the stage names to match your pipeline exactly, including capitals.
  4. Line 20 Open_Pipeline is a sample custom currency field on Accounts. Create it first.
2

Create onboarding tasks when a deal is won

Zoho CRMWorkflow rule on DealsArgument: dealId

A workflow rule can create one task. When winning a deal should start a short checklist with different due dates, a script does it in one pass and keeps the list in one place, so changing the onboarding steps later means editing one map instead of three rules.

Deluge · Zoho CRM function
deal = zoho.crm.getRecordById("Deals", dealId);
ownerId = deal.get("Owner").get("id");
steps = {"Send welcome pack":1, "Kickoff call":3, "First check-in":14};
for each subject in steps.keys()
{
	task = Map();
	task.put("Subject", subject);
	task.put("Due_Date", zoho.currentdate.addDay(steps.get(subject)).toString("yyyy-MM-dd"));
	task.put("What_Id", dealId);
	task.put("$se_module", "Deals");
	task.put("Owner", ownerId);
	zoho.crm.createRecord("Tasks", task);
}
  1. Line 3 The checklist: task name and how many days after the win it is due. Edit this line, not the loop.
  2. Line 8 Dates go to Zoho CRM as text in year-month-day form.
  3. Lines 9 and 10 What_Id plus $se_module attach the task to the deal, so it shows under the deal’s open activities.
  4. Line 12 One create call per task. Each one counts toward your daily call allowance.
3

Flag a new lead that is already a contact

Zoho CRMWorkflow rule on Leads (create)Argument: leadId

Zoho CRM’s unique-field check looks inside one module, so a web lead whose email already belongs to a customer contact slips through as a fresh lead. This script looks the email up in Contacts, ticks a checkbox and hands the lead to the person who already owns the relationship.

Deluge · Zoho CRM function
lead = zoho.crm.getRecordById("Leads", leadId);
email = ifnull(lead.get("Email"), "").trim().toLowerCase();
if(email == "")
{
	return;
}
matches = zoho.crm.searchRecords("Contacts", "(Email:equals:" + email + ")");
if(matches.size() > 0)
{
	contact = matches.get(0);
	update = Map();
	update.put("Existing_Contact", true);
	update.put("Owner", contact.get("Owner").get("id"));
	zoho.crm.updateRecord("Leads", leadId, update);
}
  1. Line 2 Trims spaces and lowers the case so “Ana@Example.com ” still matches.
  2. Line 7 Search criteria use the pattern (field:operator:value). Up to 10 conditions can be joined with and or or.
  3. Line 12 Existing_Contact is a sample checkbox on Leads. Use it in a view or a workflow alert.
  4. Line 13 Reassigns the lead to the contact’s owner. Remove this line if your assignment rules must always win.
4

Clean up names and US phone numbers

Zoho CRMWorkflow rule on Leads (create)Argument: leadId

Web forms and imports bring in “JOHN smith” and “+1 (310)555 0199.” Messy data makes mail merges look careless and breaks search. This script tidies the name into proper case and formats any 10-digit US number one way, so every phone field reads the same.

Deluge · Zoho CRM function
lead = zoho.crm.getRecordById("Leads", leadId);
update = Map();
first = ifnull(lead.get("First_Name"), "").trim();
if(first != "")
{
	update.put("First_Name", first.proper());
}
update.put("Last_Name", ifnull(lead.get("Last_Name"), "").trim().proper());
digits = ifnull(lead.get("Phone"), "").replaceAll("[^0-9]", "");
if(digits.length() == 11 && digits.startsWith("1"))
{
	digits = digits.subString(1, 11);
}
if(digits.length() == 10)
{
	update.put("Phone", "(" + digits.subString(0, 3) + ") " + digits.subString(3, 6) + "-" + digits.subString(6, 10));
}
zoho.crm.updateRecord("Leads", leadId, update);
  1. Line 6 proper() capitalizes the first letter of each word. Check names such as “McDonald” by hand afterward.
  2. Line 9 Strips everything except digits, so spaces, dots, dashes and brackets disappear.
  3. Line 10 Drops a US country code 1 at the start before formatting.
  4. Line 18 By default this update does not fire workflow rules again, so the cleanup cannot loop on itself.
5

Set a follow-up date that skips weekends

Zoho CRMWorkflow rule on Leads (create)Argument: leadId

A scheduled action fires a fixed number of days later, even if that lands on a Sunday. This script sets a Next Follow-Up date counted in business days, and gives hot sources such as web forms and chat a faster turnaround than everything else.

Deluge · Zoho CRM function
lead = zoho.crm.getRecordById("Leads", leadId);
source = ifnull(lead.get("Lead_Source"), "");
days = 3;
if(source == "Web Form" || source == "Chat")
{
	days = 1;
}
followUp = zoho.currentdate.addBusinessDay(days);
update = Map();
update.put("Next_Follow_Up", followUp.toString("yyyy-MM-dd"));
zoho.crm.updateRecord("Leads", leadId, update);
  1. Line 4 Match the source values to your own Lead Source picklist exactly.
  2. Line 8 addBusinessDay skips Saturday and Sunday by default; it can also take your own weekend days and a holiday list.
  3. Line 10 Next_Follow_Up is a sample date field. Build a view on it so each rep sees today’s calls.
6

A button that emails finance a deal summary

Zoho CRMCustom button on DealsArgument: dealId

Some steps should happen when a person decides, not when a field changes. A custom button on the deal page runs this script, sends finance the details they ask for every time, and tells the rep it worked. The text the function returns appears on screen as the confirmation.

Deluge · Zoho CRM button function
deal = zoho.crm.getRecordById("Deals", dealId);
body = "Deal: " + deal.get("Deal_Name") + "<br>";
body = body + "Amount: " + ifnull(deal.get("Amount"), 0) + "<br>";
body = body + "Close date: " + ifnull(deal.get("Closing_Date"), "not set") + "<br>";
body = body + "Owner: " + deal.get("Owner").get("name");
sendmail
[
	from: zoho.adminuserid
	to: "finance@example.com"
	subject: "Ready for invoicing: " + deal.get("Deal_Name")
	message: body
]
return "Summary sent to finance.";
  1. Line 2 The message is HTML, so line breaks are written as break tags.
  2. Line 8 Sends from the account’s admin address. You can also use the logged-in user’s address.
  3. Line 9 Replace the sample address with your finance mailbox, or read it from a field.
  4. Line 13 Button functions return text, and this is what the rep sees after clicking.
7

Send a won deal to another system’s API

Zoho CRMWorkflow rule on Deals (stage is Closed Won)Argument: dealId

When an order system, a shipping tool or your own software needs the deal the moment it closes, invokeurl posts it as JSON. The important part is the last block: if the other side refuses the call, the deal is marked so someone notices, instead of the order silently going missing.

Deluge · Zoho CRM function
deal = zoho.crm.getRecordById("Deals", dealId);
payload = Map();
payload.put("deal_id", dealId);
payload.put("name", deal.get("Deal_Name"));
payload.put("amount", deal.get("Amount"));
payload.put("account", deal.get("Account_Name").get("name"));
headers = Map();
headers.put("Content-Type", "application/json");
response = invokeurl
[
	url: "https://api.example.com/orders"
	type: POST
	body: payload.toString()
	headers: headers
	detailed: true
];
code = response.get("responseCode");
if(code != 200 && code != 201)
{
	info "Order push failed: " + response;
	flag = Map();
	flag.put("Sync_Status", "Failed");
	zoho.crm.updateRecord("Deals", dealId, flag);
}
  1. Line 11 A placeholder address. Use the endpoint your other system gives you.
  2. Line 13 Turns the map into JSON text for the request body.
  3. Line 15 detailed: true returns the status code as well as the reply, so the script can tell success from failure.
  4. Line 18 Anything other than a success code marks the deal. Sync_Status is a sample picklist.

If the other system needs a login or API key, set it up as a connection in Zoho and add connection: "your_connection" to the call. Never paste keys or tokens into the script itself.

8

Email a nightly digest of stale deals

Zoho CRMSchedule (daily)No argument

Reports show stale deals if someone opens them. A schedule sends the list instead. This script reads open deals page by page, keeps the ones with no activity in 14 days, and emails the sales manager one tidy list each morning.

Deluge · Zoho CRM schedule
staleList = List();
for each page in {1, 2, 3, 4, 5}
{
	deals = zoho.crm.getRecords("Deals", page, 200);
	for each d in deals
	{
		stage = d.get("Stage");
		touched = d.get("Last_Activity_Time");
		if(stage != "Closed Won" && stage != "Closed Lost" && touched != null)
		{
			lastDate = touched.subString(0, 10).toDate("yyyy-MM-dd");
			if(daysBetween(lastDate, zoho.currentdate) > 14)
			{
				staleList.add(d.get("Deal_Name") + " (" + d.get("Owner").get("name") + ")");
			}
		}
	}
	if(deals.size() < 200)
	{
		break;
	}
}
if(staleList.size() > 0)
{
	sendmail
	[
		from: zoho.adminuserid
		to: "sales.manager@example.com"
		subject: staleList.size() + " deals with no activity in 14 days"
		message: staleList.toString("<br>")
	]
}
  1. Line 2 Reads up to five pages of 200 deals. Raise the list for a bigger pipeline, and mind your call allowance.
  2. Line 11 The activity time arrives as date and time text, so the first 10 characters become a date.
  3. Line 18 A short page means there are no more deals, so the loop stops early.
  4. Line 30 Joins the list with line breaks so each deal sits on its own line.
9

Draft a Zoho Books invoice from a won deal

Zoho BooksWorkflow rule on Deals in Zoho CRMArgument: dealId

Retyping a won deal into accounting is where amounts get mistyped. This script runs in Zoho CRM, finds the account’s matching customer in Zoho Books and creates a draft invoice there. Finance still reviews and sends it, which is the safe default for money.

Deluge · Zoho CRM function calling Zoho Books
deal = zoho.crm.getRecordById("Deals", dealId);
account = zoho.crm.getRecordById("Accounts", deal.get("Account_Name").get("id"));
customerId = account.get("Books_Customer_ID");
if(customerId == null)
{
	info "No Books customer linked to " + account.get("Account_Name");
	return;
}
line = Map();
line.put("name", deal.get("Deal_Name"));
line.put("rate", deal.get("Amount"));
line.put("quantity", 1);
items = List();
items.add(line);
invoice = Map();
invoice.put("customer_id", customerId);
invoice.put("line_items", items);
invoice.put("reference_number", deal.get("Deal_Name"));
orgId = "YOUR_BOOKS_ORG_ID";
result = zoho.books.createRecord("invoices", orgId, invoice, "books_connection");
info result;
  1. Line 3 Books_Customer_ID is a sample field that stores the matching Books customer. The Zoho Books and CRM sync can fill it for you.
  2. Line 11 One line for the whole deal. For several products, loop through the deal’s line items instead.
  3. Line 19 Your Zoho Books organization ID, found in the Books settings.
  4. Line 20 books_connection is a connection with permission to create invoices. Create it once under connections.
10

Stop a double booking in a Zoho Creator form

Zoho CreatorForm workflow: On ValidateForm: Bookings

Creator apps often take bookings for rooms, vehicles or equipment. An On Validate script runs before the record saves, so it can refuse a booking whose times overlap another one and tell the person why. The same pattern works for any “this must not clash” rule.

Deluge · Zoho Creator form workflow
// Form: Bookings · Run when: a record is created · On Validate
if(input.End_Time <= input.Start_Time)
{
	alert "End time must be after the start time.";
	cancel submit;
}
clashes = Bookings[Room == input.Room && Start_Time < input.End_Time && End_Time > input.Start_Time];
if(clashes.count() > 0)
{
	alert "That room is already booked for part of this time.";
	cancel submit;
}
  1. Line 2 input. reads the values the person just typed into the form.
  2. Line 5 cancel submit stops the save; the alert above it explains why.
  3. Line 7 Two bookings overlap when each one starts before the other ends. This single line catches every overlap case.
  4. Also line 7 For an edit workflow, also exclude the record being edited, or it will clash with itself.

02Step by step

How do you add a Deluge function to a Zoho CRM workflow rule?

Create the function in Zoho CRM’s developer settings, give it an argument such as the deal ID, test it on one record, then attach it to a workflow rule as an instant action and map the argument to the record’s ID field.

  1. 1

    Create the function

    Go to Setup, then Developer Hub (Developer Space in some accounts), then Functions, and click New Function. Give it a clear name, such as “Deals: roll up open pipeline”, and pick the Automation category.

  2. 2

    Add the argument

    Use Edit Arguments to add dealId or leadId. The script reads the record from that ID, which keeps it reusable from buttons and Blueprint later.

  3. 3

    Paste, adapt, run once

    Paste the script, swap in your own field API names, then click Save and Execute with the ID of one test record. Read the info output before going further.

  4. 4

    Attach it to the rule

    Open or create the workflow rule, add an instant action, choose Function and pick yours. Map the argument to the module’s ID field, for example Deals, Deal Id.

  5. 5

    Test the rule end to end

    Create one record that should fire the rule and one that should not. Check the result on both, then check again after a week of real use.

03Before you write code

Do you need a Deluge script, or will a no-code tool do?

Reach for Deluge only when a workflow rule, assignment rule, Blueprint or Zoho Flow cannot do the job. Code has to be owned, tested and kept up to date, so a no-code setting that works is usually the better choice. Flip a card to see which side we would pick.

Still unsure which tool fits? Our Zoho CRM automation guide has a decision tree for workflow rules, assignment rules, Blueprint and Deluge, and our list of 10 Zoho CRM automations to set up covers the no-code side.

How do you test and debug a Deluge script?

Run it on one test record with Save and Execute, print values with info, and read the output before the script touches real data. Test the failure paths too: an empty field, a missing lookup and a refused API call.

  1. Start with a test record you can break. A sandbox is ideal if your edition has one. Otherwise, make clearly named test records and delete them afterward.
  2. Print before you write. Comment out the update or create line, run the script, and check with info that it found the right records and calculated the right values.
  3. Feed it bad data on purpose. Blank emails, deals without an account, a phone number with letters in it. Most Deluge errors come from a null value nobody expected.
  4. Check what else fires. Updates from a script can start approvals, Blueprint or, if you ask for it, workflow rules. Make sure two automations are not editing the same field.
  5. Write a one-line note at the top. What the script does, what starts it and who asked for it. The next admin will thank you.

Error messages in Deluge usually name the line number, so read the line above it as well: the real cause is often a variable that came back empty one step earlier.

What limits and mistakes should you plan for?

Every integration task call counts against a daily allowance set by your plan, calls inside loops count once per pass, lists arrive in pages of 200, and outside calls time out after 40 seconds. Most broken scripts come from ignoring one of those.

  • Calls inside loops. A loop that updates 500 records makes 500 calls. Collect the changes first and update in fewer passes where the app allows it, or run large jobs on a schedule overnight.
  • Paging. Fetch tasks return up to 200 records per page. A script that reads only page one quietly ignores record 201 onward, as in script 8.
  • Loops between automations. In Zoho CRM, zoho.crm.updateRecord does not fire workflow rules unless you pass a trigger option asking for it. If you do turn it on, make sure the rule cannot call the same script again.
  • Slow outside systems. An invokeurl call waits up to 40 seconds before it fails. Use detailed: true and handle the failure, as script 7 does.
  • Hardcoded IDs and secrets. Organization IDs, user IDs and email addresses buried in code break when anything changes. Keep them at the top of the script or in a settings record, and use connections for logins.
  • Edition limits. The number of functions, schedules and daily calls differs between Zoho editions. Check your edition before planning a script-heavy setup.

Should you write Deluge yourself or hire a developer?

Small, self-contained scripts like the ones above are a fine place for a confident admin to start. Two-way syncs, scripts that touch money, Creator apps and anything that loops over thousands of records are where an experienced Deluge developer saves rework.

A sensible split we see work: your admin owns simple scripts such as data cleanup and task creation, and a developer designs the integrations, reviews the code and leaves notes behind. If you want that help ongoing, our Zoho developer hire plans start from $300/month for one Zoho product. For a defined project, such as a set of functions or a full Zoho Creator app, we write the scope into a BRD and agree a fixed price before any code is written. Our Zoho customization service explains how that runs, and the first call costs nothing.

Want to go further on your own first? Our Zoho Creator guide shows where Creator apps fit, and our guide to hiring a Zoho developer lists the questions to ask before you hand over your account.

04Deluge questions

Zoho Deluge questions

What admins and developers ask us before they write their first Deluge function.

What is Deluge in Zoho?

Deluge is the scripting language built into Zoho’s apps. You write it in an editor inside Zoho CRM, Zoho Creator, Zoho Books and other apps, and it runs on Zoho’s servers. It reads and updates records, sends emails and calls outside systems, which covers the logic that point-and-click automation cannot.

Is Deluge hard to learn?

Not for basic scripts. There are no types to declare and no servers to manage, and most work uses built-in tasks such as getRecordById and updateRecord. Anyone who has written spreadsheet formulas or a little JavaScript can adapt simple scripts quickly. Integrations, paging and error handling take more experience.

Where do I write and test a Deluge script in Zoho CRM?

Go to Setup, then Developer Hub, then Functions, and create a new function. Add an argument such as the record ID, paste the script and click Save and Execute with one test record. Values you print with info appear in the output panel, so you can check the script before attaching it to a workflow rule or button.

Can Deluge call an external API?

Yes. The invokeurl task sends GET, POST, PUT and other requests with headers and a body, and returns the reply. Use a Zoho connection for logins and API keys instead of writing them into the script, set detailed to true to read the status code, and plan for the 40-second timeout.

Does zoho.crm.updateRecord trigger workflow rules?

Not by default. An update from Deluge runs approvals, Blueprint and orchestration, but workflow rules fire only if you pass a trigger option that asks for them. That default prevents most accidental loops. If you turn workflow triggers on, make sure the rule cannot start the same script again.

Can I paste these Deluge script examples into my account as they are?

Treat them as starting points. Field names such as Open_Pipeline, Existing_Contact and Books_Customer_ID are samples, and stage names, picklist values and email addresses must match your own setup. Change those, test on one record, then attach the script to a rule or button.

Which Zoho apps support Deluge?

Zoho Creator, Zoho CRM, Zoho Books, Zoho Desk, Zoho Flow and many other Zoho apps support Deluge in some form, usually as custom functions. The language is the same, but each app has its own built-in variables and triggers, so a script may need small changes when it moves between apps.

Does Deluge cost extra?

Deluge itself comes with the Zoho apps. What you can do with it depends on your plan: the number of functions, schedules and daily integration calls differs between editions. Check your edition’s limits before you plan many scripts, especially ones that run on large record sets.

05Let’s talk

Tell us what you’re building. We’ll map the fix.

Book a 30-minute discovery call with Elite Tech Global. We review your Zoho, AWS, Shopify or WordPress setup, show where AI agents can save time, and agree the next step. If we work together, every requirement and a fixed price go into a signed BRD before the build starts.

Real people, one team. Led by co-founders Ikramul Karim and Khris Kakosimidi, and a 40+ member team across Zoho, AWS and AI.

Book a 30-minute discovery call

Tell us a little and we’ll email you to set up the call.

What can we help with?

No spam. We use your details to reply about your project, and send occasional updates only if you tick the box above. See our Privacy Policy.