Countries around the world use different numbering formats that employ commas and decimals differently. For example, the United States uses a comma (,) as a thousands separator, while Germany uses a period (.). Conversely, for decimals, the United States uses a period (.), whereas Germany uses a comma (,). Thus, the number three thousand twenty-five and eight tenths appears as 3,025.8 in the US and 3.025,8 in Germany.
These conventions highlight the importance of displaying monetary amounts in both numerical and written formats in formal business documents, such as invoices. This dual representation helps prevent fraud, reduces ambiguity caused by regional formatting differences, and adds a professional touch to your invoices.
Wouldn't it be great if you could automatically display grand totals in words alongside their numerical values in invoices? A custom function can help you do just that. Simply create a function that auto-populates the total amount in words in a custom field and link it to a workflow rule that triggers whenever an invoice is created or updated.
Permissions and availability
- Users with the Manage Extensibility permission can create connections and write custom functions.
- Users with the Modules Customization permission can add custom fields.
- Users with the Manage Automation permission can create and update workflow rules.
- Users with Manage Sandbox permissions can manage the sandbox.
Requirements
- Create a Zoho CRM connection with the required scope as detailed in the "Create a connection" section below. Learn more
- Add a custom single-line field to the Invoices module. This field will hold the invoice grand total in words. Learn more
- Create a workflow rule for the Invoices module that triggers every time an invoice is created or edited. Learn more
- Write a custom Deluge function that updates the grand total of invoices in words, and link it to the workflow rule. Learn more
- Test the workflow rule in a sandbox before deploying it to your production environment. Learn more
Create a connection
The first step is to create a connection in your Zoho CRM account.
- Navigate to Setup > Developer Hub > Connections.
- Click CreateConnection.
- Select Zoho CRM under Default Services.
- Specify a Connection Name.
You will need to enter this name in the code snippet below. - Select the following Scope to request access.
- ZohoCRM.modules.all
- Click Create and Connect.
- Click Connect, then click Accept to confirm access to the requested scope.
Add a custom field
The next step is to add a single-line field to the Invoices module.
- Navigate to Setup > Customization > Modules and Fields.
- Click the Invoices module to open the layout editor.
- Drag and drop the single-line field from the New Fields tray to the desired section of the layout.
- Name the single-line field (e.g., "Grand Total (in Words)"), define its properties as required, then click Done.
- Once you've finished, click Save and Close.
Create a workflow rule
The final step is to create a workflow rule and connect it with a custom function.
- Navigate to Setup > Workflow Rules > +Create Rule.
- Select the Module as Invoices from the dropdown list.
- Provide a name for the rule. For example: "Update invoice grand total in words".
- Add a description, if required, then click Next.
- In the Execute this workflow rule based on section, do the following:
- Choose Record Action, then select Create or Edit from the dropdown.
- Check the box for Repeat this workflow whenever a invoice is edited option.
- Click Next.
- In the Which invoices would you like to apply the rule to? section, specify the condition as "<Grand Total> <is not empty>", then click Next.
- Under Instant Actions, select Function and Write your own.
- Provide a name for the function, as well as a description, if necessary.
- In the Deluge Script Editor, do the following:
- Copy and paste the code provided below.
- Click Edit Arguments.
- Enter the name as invoiceId, and select the value as Invoices - Invoice Id.
- Click Save, then click Save & Execute Script.
- Click Save on the workflow rule page.
The code
invoiceDetails = zoho.crm.getRecordById("Invoices",input.invoiceId.toLong());
val_s = ifnull(invoiceDetails.get("Grand_Total"),"0");
//val_s=input.val.toString();
th = {"","thousand","million","billion","trillion"};
// uncomment this line for English Number System
// th = {"","thousand","million", "milliard","billion"};
dg = {"zero","one","two","three","four","five","six","seven","eight","nine"};
tn = {"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
tw = {"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
x = val_s.length();
if(x > 15)
{
info "too big";
}
else
{
s = val_s.replaceAll("(?)",",",false).removeFirstOccurence(",").removeLastOccurence(",").toList();
str = "";
sk = 1;
bypass = false;
for each index i in s
{
cur = s.get(i).toLong();
info cur;
if(!bypass)
{
if((x - i) % 3 == 2)
{
if(cur == 1)
{
next = s.get(i + 1).toLong();
info next;
str = str + tn.get(next) + " ";
bypass = true;
sk = 1;
}
else if(cur != 0)
{
str = str + tw.get(cur - 2) + " ";
info str;
sk = 1;
}
}
else if(cur != 0)
{
str = str + dg.get(cur) + " ";
info str;
if((x - i) % 3 == 0)
{
str = str + "hundred ";
sk = 1;
}
}
}
else
{
bypass = false;
}
if((x - i) % 3 == 1)
{
if(sk != 0)
{
str = str + th.get(floor((x - i - 1) / 3)) + " ";
info str;
sk = 0;
}
}
}
info str;
}
upperstr = str.toUpperCase();
mp = Map();
mp.put("Grand_Total_in_Words",upperstr);
dlist = List();
dlist.add(mp);
dmp = Map();
dmp.put("data",dlist);
update = invokeurl
[
url :"https://www.zohoapis.com/crm/v7/Invoices/" + invoiceId
type :PUT
parameters:dmp + ""
connection:"connectionname"
];
info dmp;
info update;Notes
- Make sure to use the accurate API name of the fields used in the code snippet (e.g., "Grand Total (in Words)"). Learn more
- Replace "connectionname" with the name of the Zoho CRM connection (see the "Create a connection" section above).
- Change the URL endpoint to match the data center of your account. For example, https://www.zohoapis.in/... for India.
- The function applies only to whole numbers with a maximum of 15 digits.
- For European number systems, make sure to uncomment the alternative "th" array in the code.
- The code above demonstrates how to automatically populate the invoice grand total in words and thereby avoid ambiguities caused by regional formatting differences. You can use this code for any other module, such as Quotes, Sales Orders, and Purchase Orders, by modifying the module name and other parameters.
Tips
- Use the ${Grand_Total_in_Words} merge field in your invoice templates to automatically display the total amount in words when sending client-facing documents.
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
Test the solution
- Navigate to Invoices > +Create Invoice.
- On the Invoice Details page, enter the required fields and add items to calculate the Grand Total, then click Save.
The workflow rule will be triggered. - Check whether the Grand Total (in Words) field is updated to reflect the amount in words.
- Edit an existing invoice's grand total and verify that the words update accordingly.
Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.
More info
- ModuleInvoices
- Trigger PointWorkflow Rule
- EditionEnterprise and above
- ComplexityHigh
- Implementation Time60 minutes

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST