Function-13: Add Invoice grand total in words with the click of a button

Function-13: Add Invoice grand total in words with the click of a button


Welcome back everyone!

Last week, we learnt how to add pre-defined notes in a click. This week, let's look at a custom function that helps you add the invoice grand total in words with the click of a button.

Business scenario:

Countries across the globe follow different numbering formats with comma and decimals being used interchangeably:

  • In the US, comma (,) is used as thousands separators where as in Germany, period (.) is used. 
  • In the US, period (.) is used as decimal separator where as in Germany, comma (,) is used. 

Thus, three thousand fifty-five and eight tenths is displayed as 3,025.8 in the US and 3.025,8 in Germany. For cheques, the practice of writing the amount in words not only helps avert malpractice, but also clears any discrepancies associated with number format. If you are dealing with multi-national clients, it is best to extend this practice to your client invoices, and this weeks custom function helps you achieve just that with the click of a button.


Getting started with the custom function:
  1. Go to Setup > Automation > Actions > Custom Functions > Configure Custom Function > Write your own .
  2. Provide a name for the button. For example: “Total in words”. Add a description(optional).
  3. Choose the module as " Invoice ".
  4. Click “ Free flow scripting ”.
  5. Copy the code given below.
  6. Click “ Edit arguments ”.
  7. Enter the name as “ invoiceId ” and select the value as “ Invoice Id ”.
  8. Save the changes.
  9. Click Save to create the button.

The script:

Code for Version 2.0 API:
 
invoiceDetails = zoho.crm.getRecordById("Invoices", input.invoiceId.toLong()); 
val_s = ifnull(invoiceDetails.get("Grand_Total"),"0").toLong();
//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);
update = zoho.crm.update("Invoices", invoiceId.toLong(), mp);
info mp;
info update;

Code for Version 1.0 API:

invoiceIdStr = input.invoiceId.toString();
invoiceDetails = zoho.crm.getRecordById("Invoices", input.invoiceId);
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);
update = zoho.crm.updateRecord("Invoices", invoiceIdStr, mp);
info mp;
info update;

This is how the result looks like:

 
Note:

  • Create a custom field named 'Grand Total (in Words)' in your invoice module. Note that this is part of the code (mp.put("Grand Total (in Words)", upperstr);). Just in case you use a different field name, update the code accordingly.
  • The above code adds the grand total in words in your invoice record.
  • Use merge fields to reflect the same in the invoice templates to be sent to your clients
  • This custom function handles up to 15 digits and rounds-off to the nearest whole number.

Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful. Do check out other custom functions shared in this serieshere.

See you all next week with another interesting custom function. Ciao!

Update: As you must be aware, API V1.0 will be deprecated and support for version 1.0 API will be available only till Dec 31, 2018. Version 1.0 compatible Functions will continue to work until Dec 31, 2019. You're advised to migrated to API Version 2.0 at the earliest. Check this announcement for more. We've updated the post to include the Version 2.0 compatible Function.

      • Sticky Posts

      • Zoho CRM Functions 53: Automatically name your Deals during lead conversion.

        Welcome back everyone! Last week's function was about automatically updating the recent Event date in the Accounts module. This week, it's going to be about automatically giving a custom Deal name whenever a lead is converted. Business scenario Deals are the most important records in CRM. After successful prospecting, the sales cycle is followed by deal creation, follow-up, and its subsequent closure. Being a critical function of your sales cycle, it's good to follow certain best practices. One such
      • User Tips: Auto-Create Opportunity/Deal upon Quote Save (PART 1)

        Problem: We use quotes which convert to sales orders but Users / Sales Reps do not create opportunities / deals and go straight to creating a quote. This leads to poor reporting. Implementing this solution improves reporting and makes it easier for users.
      • Custom Function : Automatically send the Quote to the related contact

        Scenario: Automatically send the Quote to the related contact.  We create Quotes for customers regularly and when we want to send the quote to the customer, we have to send it manually. We can automate this, using Custom Functions. Based on a criteria, you can trigger a workflow rule and the custom function associated to the rule and automatically send the quote to customer through an email. Please note that the quote will be sent as an inline email content and not as a PDF attachment. Please follow
      • Function #50: Schedule Calls to records

        Welcome back everyone! Last week's function was about changing ownership of multiple records concurrently. This week, it's going to be about scheduling calls for records in various modules. Business scenario Calls are an integral part of most sales routines.. Sales, Management, Support, all the branches of the business structure would work in cohesion only through calls. You could say they are akin to engine oil, which is required by the engine to make all of it's components function perfectly. CRM
      • Function #37: Create a Purchase Order from a Quote

        Welcome back everyone! Last week, we learnt how to calculate the total number of activities for a lead and further take note of the activity count for particular dates. For instance, from the period of Demo to Negotiation. This week, let's look at a function that lets you create a Purchase Order instantly from a Quote. Business scenario: In any form of business, one of the most important things to do is to document the transactions. Naturally, negotiation, signing an agreement, placing an order,

        • Recent Topics

        • Power of Automation :: Quick way to associate your Projects with Zoho CRM

          A custom function is a software code that can be used to automate a process and this allows you to automate a notification, call a webhook, or perform logic immediately after a workflow rule is triggered. This feature helps to automate complex tasks and
        • Date triggering Workflow rule

          I have a function triggered by a workflow rule. The function takes a date and creates a task for that date and fills in a field with the name of the day for that date. It also updates the status field of the record. The workflow rule is set to run whenever
        • Restricting contact creation

          Hi all! I am looking to use Zoho Desk in a part of the business that takes end user enquiries. These are generally single interactions, and not linked to an account name. As Desk is Account centric, has anyone designed a way to manage these incoming emails
        • Import Holiday Calendars

          HI Zoho Is there anyway of importing an online calendar like https://www.calendarlabs.com into the business hours calendars, to speed up setup of holiday calendars. Also could we also request a feature where you can specify a Holiday as hours, i.e it could be that the company is on a 1/2 day due to a holiday or when it is Eid in the UAE and they are only allowed to work restricted hours so we need the calendar to be flexible to allow for this. Regards Jamie
        • Filtering Tickets based on Email headers

          We're starting to get a lot more junk coming into our Zoho Desk, which is then triggering unnecessary email alerts to agents. Once thing we could do to cut this junk in half, is to filter tickets based on email headers. Any email containing the `List-Unsubscribe`
        • Error 550 5.4.1

          I’ve tried sending an email to someone but keep receiving this back. Any help would be greatly appreciated 
        • Billing Management: #2 Fair way of Billing- Prorated Billing

          Hello, From speaking about the traditional ways of billing in the previous post, we are moving into the deep sea of billing. We are now in a zone to break out the most complex yet, I would call it the fairest way of billing, the Prorated Billing. Prorated
        • Has Anyone successfully integrated Zoho and Sage Intact?

          Hey all, We’re evaluating Zoho One + Sage Intacct and I’m trying to connect with anyone who has actually implemented the two together.Specifically, I’d love to know: -- Which functions you kept in Zoho vs. Intacct (e.g., Product Catalog, AR/AP, invoicing,
        • How can I filter a field integration?

          Hi,  I have a field integration from CRM "Products" in a form, and I have three product Categories in CRM. I only need to see Products of a category. Thanks for you answers.
        • Adding image in HTML report page

          Hi, I want to know two things: 1. Can anyone advise how to add an image in HTML report. The tagged used is <img> but what path do I mention for the image to be added in the HTML report. 2. Also, I want to know if I am creating an application for the market
        • How to change view of HTML report based on device but always print in A4

          Hello everyone, I am aware that HTML report view can be configured to adjust according to the screen size like Laptop, Tablet and mobile using media queries. But my concern is no matter on which device the reports is opened when printed should always
        • Age Calculation

          I've attempted to calculate the age of someone based on their birthday input by using the formula field. It works but I don't want all those decimals on there. I then tried to use "set variable" after birthday input but I get a field type mismatch, long vs. floating. Any ideas would be wonderful.
        • Search on Custom Field

          We're working on an integration with the Zoho FSM API and are trying to retrieve companies based on a custom field we added to the Companies module. However, we can't find a way to filter or query records using custom fields through the API. We have a
        • Sendmail function / custom action?

          I've setup a function hoping to email various business departments the details of a record once all work in that record is complete so gone about setting up a custom action in such way that each record line on the report has a button to click. Question is how do I actually include data from that record in the email that is sent when the button is clicked? I had thought that since this were being sent per record the email would include the data which had been entered
        • API to post drafts for social media

          I we want to post draft posts to our zoho social account and then approve and schedule them within Zoho social. is this possible with for example: https://apis.zoho.com/social/v2/post TIA Jon
        • Canvas View in Zoho Recruit

          Is it possible or would it be possible to have the new 'Canvas View' in Zoho Recruit?
        • What impactful sales coaching techniques have you used to boost your team's performance?

          I'm curious about the real-world impact of sales coaching on team performance. What specific techniques or strategies have you found most effective in driving consistent improvement and growth in your sales team? Any success stories or lessons learned
        • Adding Taxes to paid consultations in Zoho Bookings

          I created a 'paid' consultation under Zoho Booking and integrated it with payment gateways for online/instant payment before a booking is done. How can I add 'taxes' to the price of consultation? I can add taxes to other Zoho apps (liks Books, Checkout,
        • Zoho Finance Suite - Customer Custom Tabs - Dynamic Link

          Hi Finance Suite team, When creating a Custom Tab for a Client Portal, there is no option to add dynamic parameters. This would be very helpful for adding Zoho Analytics dashboards which can be dynamically filtered through the URL to only show information
        • Possible to bold or indent text in the description field?

          As part of one item, I often have a detailed description that would be much easier to read if there was the ability to have a bulleted list or bold text and the like. Is this possible? My last invoicing software allowed markup in the field so, for example, an asterisk meant a bullet. I haven't been able to find any documentation related to this.  Any information would be appreciated. Thank you.
        • How can I setup Zoho MCP with Chat GPT

          I can set up custom connections with Chat GPT but I cat an error when I try to set it up. The error is: "This MCP server can't be used by ChatGPT to search information because it doesn't implement our specification: search action not found" Thoughts?
        • Formatting of Balance Sheet and Profit & Loss Reports

          The default format of the Balance Sheet and P&L Reports are based on the Account Types and then the individual accounts within the Chart of Accounts. These are then ordered alphabetically under these sub-headings and one is unable to re-order these or
        • UK MTD reports concerning turnover and cerash accounting

          Hi I am a sole trader, and I have just started with Zoho Books in order to comply with the new HMRC requirements. I use 'cash basis' - which I understand to mean that income is when the cash comes in (not the invoice date) and expenses are when they are
        • Retainer Invoice.

          Why ZOHO not have facilities to deduct partially advance payment from an invoice.
        • IMAP Server not responding.

          Trying to connect a phone via IMAP and getting "imap.zoho.com not responding." Is the server down, for maintenance or otherwise? I've tried this on two different devices and got the same error on both.
        • Share saved filters between others

          Hi, I am in charge to setup all zoho system in our company. I am preparing saved filters for everybody, but the only one can see its me. How can others see it? Thanks
        • GST Slabs Redefined: Stay Compliant Using Zoho Books!

          Hello Everyone! The Government of India is rolling out new GST rates, a major reform aimed at simplifying the current tax structure starting 22 September 2025. GST will move from four slabs (5%, 12%, 18%, 28%) to two main slabs (5% and 18%), plus a special
        • Kanban view on Zoho CRM mobile app!

          What is Kanban? The name doesn't sound English, right? Yes, Kanban is a Japanese word which means 'Card you can see'. As per the meaning, Kanban in CRM is a type of list view in which the records will be displayed in cards and categorized under the given
        • Presenting ABM for Zoho CRM: Expand and retain your customers with precision

          Picture this scenario: You're a growing SaaS company ready to launch a powerful business suite, and are looking to gain traction and momentum. But as a business with a tight budget, you know acquiring new customers is slow, expensive, and often delivers
        • No practical examples of how survey data is analyzed

          There are no examples of analysis with analytics of zoho survey data. Only survey meta data is analyzed, such as number of completes, not actual analysis of responses, such as the % in each gender, cross-tabulations of survey responses. One strange characteristic
        • Zoho Creator as LMS and Membership Solution

          My client is interested in using Zoho One apps to deploy their membership academy offer. Zoho Creator was an option that came up in my research: Here are the components of the program/offer: 1. Membership portal - individual login credentials for each
        • Adding Chargebee as a Data Connector

          Is it possible to get Chargebee added as a Zoho Analytics data connector?
        • Webform & spam

          Hi, We set up 2 webform on our website, fowarding the content to Zoho CRM. Since it has been opened up, we are getting lot of spam message (for now about 20 a day). To lower the  amount of false new leads we added the captcha field and new enquieries are send to the Approval Leads list. However we still get some spam. Is there any "anti spam" mechanism built in Zoho CRM, or how is the best way to avoid these kind of spam ? Thanks
        • Dropbox to Workdrive

          Namaste, Trust you all are doing well. Wanted to check how this can be done with Zoho flow. I typically receive dropbox links from my clients. Is there a way where I can provide the link to Zoho flow and it downloads the files from dropbox link to a work
        • Deals by Stages Funnel not showing in correct order

          Using the Stage-Probability Mapping for the Deals module we have created a steps our deals will pass through, RFQ, Closed/Lost, Declined/No-Go, Pricing, Submitted, Negotiations, Won. However when I view the Deal By Stages Funnel it does not show in the
        • Turning off the new UI

          Tried the new 'enhanced' UI and actively dislike it. Anyone know how to revert back?
        • Confirmation prompt before a custom button action is triggered

          Have you ever created a custom button and just hoped that you/your users are prompted first to confirm the action? Well, Zoho knows this concept. For example, in blueprint, whenever we want to advance to the next state by clicking the transition, it is
        • How to create auto populate field based on custom module in Zoho CRM?

          Hello, i'm still new to Zoho CRM and work as administrator in my company. Currently, I'm configuring layout for Quotes Module. So, the idea is, I've created a read-only field in Quotes called "Spec". I want this field automatically filled with Specification
        • Rich Text For Notes in Zoho CRM

          Hello everyone, As you know, notes are essential for recording information and ensuring smooth communication across your records. With our latest update, you can now use Rich Text formatting to organize and structure your notes more efficiently. By using
        • Change Last Name to not required in Leads

          I would like to upload 500 target companies as leads but I don't yet have contact people for them. Can you enable the option for me to turn this requirement off to need a Second Name? Moderation update (10-Jun-23): As we explore potential solutions for
        • Next Page