Core Idea
Suppose you have a subform called Items in Deals. On a click of a button, you want to generate a PDF document via Zoho Writer with the subform rows merged into a table. If the number of rows in the table is fixed, you can create the table on the Writer template, set plain text merge fields as the table values, and merge it with Deluge. However, if the number of rows in the table varies, you need to dynamically create the table in Deluge, then merge the entire table into the Writer template via a Rich Text Field.Tutorial
Create a Rich Text Merge Field on Your Writer Template
On the side toolbar, go to Fields –> Merge Fields (Under Dynamic Fields) –> Click on Create Fields –> Add a New Field (Rich Text) In this example, the rich text field label is “table”.
Write Your Deluge Function
Get the Subform
Change “Items” to your respective subform name.This is just an example. For your application, it could be a subform, related list, or any other types of list.
deal = zoho.crm.getRecordsbyId("Deals",dealid);
items = deal.get("Items");
Build the Table
The meat of the script starts here. Once you have your list (in this example, Items subform), do the following:
Set the Headers for the Table & Define the Counters
- headers: Start building your table here by creating the headers and customizing the table properties (cellpading/cellspacing/width/background color/etc).
- In this table example, the headers are Name, SKU, Serial Number and Quantity.
- bodytext: Set to an empty string. This will be used to build the rows of the table.
- n: Set it as 0. This will be used later to alternate the table row colors.
headers = " Name SKU Serial Number Quantity ";
bodytext = "";
n = 0;
Iterate through the List & Build the Table Rows
- Get the Name, SKU, Serial Number and Quantity values for each element of the list.
- Insert the script that alternates row colors. You can customize the row color to anything you desire, just specify the hex code.
- At each iteration, we +1 to n.
- Then, define hex with an if condition that sets that value in an alternating pattern with the isOdd function.
- Build the table row with the bodytext variable.
- Finally, outside the loop, combine the headers and bodytext and add a command to close the table.
for each i in items
{
name = i.get("Name");
SKU = i.get("SKU");
serial = i.get("Serial_Number");
quantity = i.get("Quantity");
// This gives the table rows alternating colours
n = n + 1;
if(isOdd(n))
{
hex = "FFFFFF";
}
else
{
hex = "F3F6F9";
}
// Build the bodytext for the table
bodytext = bodytext + "" + name + " " + SKU + " " + cereal + " " + quantity + " ";
}
fulltable = headers + bodytext + "
";
info fulltable;
- You now have the full table that should look like this:
Merge the fulltable variable into the Rich Text Field
Your HTML table is ready. Just merge it into the Rich Text Merge Field in your Zoho Writer template, and you’re good to go!
Click here to copy these scripts. For more Zoho-wizardry, check out our GitHub page.
Contact Us!
Book a free 30-minutes consultation with a Zoho expert or send us an email

Related Resources
This set up allows you to insert subform rows and add to picklist dynamically with...
Deluge script for sorting lists containing maps by the specific key (by date-time/alphabetical...
When scripting, ask yourself this question - will this value ever be null? If it's...
This script allows you to create a HTML table in Deluge with dynamic rows, then merge...
When a Zoho CRM record is created/updated/deleted via Deluge, the system does not...
Click Here to Apply
Description
Location
Bastrop/Smithville area
Role
Entry...
Click Here to Apply
Description
Location
New Braunfels area
Role
The Partner...
This tutorial will illustrate how to create a custom function (using Deluge scripting)...
This tutorial demonstrates the integration between Shopify and Zoho Inventory. Use...
This tutorial provides a Creator script that loads related records from Zoho CRM...