Function-4: Get the total quantity, taxes and discounts for a record at a glance!

Function-4: Get the total quantity, taxes and discounts for a record at a glance!




Welcome back folks!

Last week, we learnt about auto-update of account information across CRM. This week, let's look at a custom function that makes accounting and report generation easier by automatically calculating the amount of tax, discounts and the quantity of items for a particular record in a quote, invoice, purchase order or sales order.

Business scenario:

I'm sure you agree that meticulous tracking and management is critical for your business to hold up and flourish. You need to keep an inventory of items and products you have or deal with. The other important aspects of the transactions that need keeping a tab on, are taxes and discounts associated with records in a quote, purchase order or sales order. Do you want to manually do that on your own? Of course not. This custom function helps automate just that. It sums up the total amount of tax to be paid and the discount given to the customer, and lists the total quantity of products involved in the deal.

The quotes, sales order, purchase order and invoices of a deal are tracked in your CRM solution. Add this custom function to any or all of the four modules. See the total taxes, discounts, and quantity of products against the records.
Let's assume an example of calculating the taxes and discounts for a record in the Quotes module.



The above record displays the products involved in the deal in the "Product details" section and the "Line Item totals" section is where the total tax, discounts, and total quantity of products are displayed.

Pre-requisite: Create the custom fields, "Total Tax at line item level", "Total discount at line item level" and "Total quantity".

Getting started with the custom function:

  • Go to Setup>Automations>Actions >Custom Functions > Configure Custom Function > Write your own.
  • Provide a name for the Custom function. For example: “Sumup line items field values”.
  • Select the module as Quotes. Add a description(optional).
  • Click “Free flow scripting”.
  • Copy the code given below.
  • Click “Edit arguments”.
  • Enter the name as “quoteId” and select the value as “Quote Id”.
  • Save the changes.

The script:

Code for Version 2.0 API:
 
1) For total tax: 

respMap = zoho.crm.getRecordById("Quotes", input.quoteId.toLong());
productDet = ifnull(respMap.get("Product_Details"),"");
linetaxes = 0.0;
for each eachProd in productDet
{
linetax = (ifnull(eachProd.get("Tax"),"0.0")).toDecimal();
linetaxes = (linetaxes + linetax);
}
paramap = map();
paramap.put("Total_Tax_at_line_item_level", linetaxes);
updateResp = zoho.crm.updateRecord("Quotes", quoteId.toLong(), paramap);
info paramap;
info updateResp;

2) For total discount : 

quoteIdStr = input.quoteId.toString();
respMap = zoho.crm.getRecordById("Quotes", input.quoteId.toLong());
productDet = ifnull(respMap.get("Product_Details"),"");
linediscount = 0.0;
for each eachProd in productDet
{
linedis = (ifnull(eachProd.get("Discount"),"0.0")).toDecimal();
info linedis;
linediscount = (linediscount + linedis);
}
paramap = map();
paramap.put("Total_Discount_at_line_item_level", linediscount);
updateResp = zoho.crm.update("Quotes", quoteId.toLong(), paramap);
info paramap;
info updateResp;

3) For total quantity : 

quoteIdStr = input.quoteId.toString();
quoteMap = zoho.crm.getRecordById("Quotes", input.quoteId.toLong());
productDet = ifnull(quoteMap.get("Product_Details"),"");
value = 0;
for each eachProd in productDet
{
qty = (ifnull(eachProd.get("quantity"),"0")).toLong();
value = value + qty ;
}
params = map();
params.put("Total_Quantity", value);
updateResp = zoho.crm.update("Quotes", quoteId.toLong(), params);
info params;
info updateResp;

Code for Version 1.0 API:

1) For total tax:

quoteIdStr = input.quoteId.toString();
respMap = zoho.crm.getRecordById("Quotes", input.quoteId);
productDet = ifnull(respMap.get("product"),"");
productList = productDet.toJSONList();
linetaxes = 0.0;
for each eachProd in productList
{
eachProdDet = eachProd.toMap();
linetax = (ifnull(eachProdDet.get("Tax"),"0.0")).toDecimal();
linetaxes = (linetaxes + linetax);
}
paramap = map();
paramap.put("Total Tax at line item level", linetaxes);
updateResp = zoho.crm.updateRecord("Quotes", quoteIdStr, paramap);
info paramap;
info updateResp;

2) For total discount :

quoteIdStr = input.quoteId.toString();
respMap = zoho.crm.getRecordById("Quotes", input.quoteId);
productDet = ifnull(respMap.get("product"),"");
productList = productDet.toJSONList();
linediscount = 0.0;
for each eachProd in productList
{
eachProdDet = eachProd.toMap();
linedis = (ifnull(eachProdDet.get("Discount"),"0.0")).toDecimal();
info linedis;
linediscount = (linediscount + linedis);
}
paramap = map();
paramap.put("Total Discount at line-item level", linediscount);
updateResp = zoho.crm.updateRecord("Quotes", quoteIdStr, paramap);
info paramap;
info updateResp;


3) For total quantity :

quoteIdStr = input.quoteId.toString();
quoteMap = zoho.crm.getRecordById("Quotes", input.quoteId);
productDet = ifnull(quoteMap.get("product"),"");
productList = productDet.toJSONList();
value = 0;
for each eachProd in productList
{
eachProdDet = eachProd.toMap();
qty = (ifnull(eachProdDet.get("Quantity"),"0")).toLong();
value = value + qty ;
}
params = map();
params.put("Total Quantity", value);
updateResp = zoho.crm.updateRecord("Quotes", quoteIdStr, params);
info params;
info updateResp;

Note:

  • To add this custom function to the other modules such as SalesOrders, Invoices, or PurchaseOrders, make sure you replace the module name Quote to the desired module name in the snippet above.

Found this useful? Try 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. 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.

    Access your files securely from anywhere







                            Zoho Developer Community




                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                  • Ask the Experts



                                                            • Sticky Posts

                                                            • Function #46: Auto-Calculate Sales Margin on a Quote

                                                              Welcome back everyone! Last week's function was about displaying the discount amount in words. This week, it's going to be about automatically calculating the sales margin for a particular quote, sales order or an invoice. Business scenario Where there is sales, there's also evaluation and competition between sales reps. A healthy rivalry helps to better motivate your employees to do smart work and close deals faster and more efficiently. But how does a sales rep get evaluated? 90% of the time, it's
                                                            • 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


                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner







                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources

                                                                                              Zoho Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ




                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方







                                                                                                              • Recent Topics

                                                                                                              • Tip #50- A Closer Look at the Unattended Access Dashboard- 'Insider Insights'

                                                                                                                Having complete visibility and quick access to everything you need certainly makes managing multiple remote devices a lot easier, and that is precisely what the Unattended Access Dashboard in Zoho Assist is designed to offer. Once you go to the Unattended
                                                                                                              • How to update custom multi-user field in Zoho Projects?

                                                                                                                I'm trying to update custom multi-user fields in Zoho Projects via a Deluge function in CRM. The code I have so far is below. It works for updating standard project fields and single-line custom fields, but it does not work to update multi-user fields.
                                                                                                              • Tip of the Week #75– Manage your social media messages from a single shared inbox.

                                                                                                                Are you tired of jumping between apps or browser tabs to reply to your business's Facebook and Instagram DMs? Handling customer messages on social media might seem simple, but switching between multiple platforms can easily lead to lost messages, duplicate
                                                                                                              • Zoho Map integration tasks have changed - you need to "Locate all instances of Zoho Map integration tasks in your Deluge scripts by searching for the v1 marker... before 16 January 2026"

                                                                                                                The Zoho Map deluge integration task has been changed (as at 21 October 2025) to provide a more structured, JSON-like response. This change affects all three Zoho Map integration tasks (Geocode, Reverse Geocode, and Distance Between). More details can
                                                                                                              • Using files from Zoho CRM in Gemini/ChatGPT/Claude

                                                                                                                Hi all, I’ve got subscriptions to Gemini and a few other AI tools which I use for tasks like data enrichment, email composition, etc. In our workflow, we often receive various documents from clients — such as process workflows, BRDs/requirement documents
                                                                                                              • Zoho Analytics & Zoho Creator - Modified Time value

                                                                                                                I'm trying to use the Zoho Creator system field 'modified time' in Zoho Analytics, but it's consistently showing 12 hours 'out' In Zoho Creator In Zoho Analytics Is this a constant difference that I just need to correct with a timezone change - or is
                                                                                                              • Zoho CRM - Option to create Follow-Up Task

                                                                                                                When completing a Zoho CRM Task, it would be very helpful if there was an option to "Complete and Create Follow-Up Task" in the pop-up which appears. It could clone the task you are closing and then show it on the screen in edit mode, all the user would
                                                                                                              • Portal For Different Apps

                                                                                                                I found some older threads on this but didn't see anything very recent. I'm new to Zoho One so forgive me if my terminology is off a bit. I was hoping set up a single point of entry into Zoho One. So, many of the apps could be found in one single place
                                                                                                              • Calls undetected

                                                                                                                Zoho Voice records indicate my last call ended at 6:00 PM. All incoming and outgoing calls occurred between 6:00 PM and 7:00 PM.
                                                                                                              • Unable to Select Authenticated Domain as Sender

                                                                                                                We’ve already authenticated our domain, but it’s still not appearing in the sender list when we try to run a campaign. Could you please check what might be causing this issue?
                                                                                                              • Zoho Projects - Project Details on the Project Menu

                                                                                                                Hi Project's team, I've helped may businesses setup and use Zoho Project and one thing I see time and time again is confusion on where to find the Project Details information. I would be much more intuitive if Project Details was on the menu before Dashboard.
                                                                                                              • Introducing WhatsApp integration in Bigin

                                                                                                                Greetings! In today's business landscape, messaging apps play a significant role in customer operations. Customers can engage with businesses, seek support, ask questions, receive personalized recommendations, read reviews, and even make purchases—all
                                                                                                              • Zoho Projects - Show Task List as dropdown field on Task records

                                                                                                                Hi Project's Team, I noticed today that there is no field on a task record related to the task list it belongs to. A dropdown would be helpful for quickly moving tasks between lists while in a task. I know that you can go to "Other Actions" and choose
                                                                                                              • My followed tickets extension is not working under the All departments view

                                                                                                                Hi. I've installed the My followed tickets extension. However, when I try to open the extension under the all departments view, I get the following message: 'Sorry, this extension is not supported in the All Departments view.' How can I solve this p
                                                                                                              • Ticket Time Entry to Timesheet

                                                                                                                The title just about sums it up. I have searched here and not found anything relevant, but If I overlooked, then please set me straight.  We have staff that do nothing but close tickets in desk all day long. These tickets represent their timesheet. Is there a way to have this information sync or for a tech to go into their timesheet themselves and sync it with their tickets of the same timeframe?? We waste a ton of time doing timesheets and the old "Clock in/Clock out" isnt detailed enough for us!!
                                                                                                              • Calls undetected.

                                                                                                                The call is not showing on the call log.
                                                                                                              • Calls undetected

                                                                                                                Zoho is not reading calls made.
                                                                                                              • Multi-currency and Products

                                                                                                                One of the main reasons I have gone down the Zoho route is because I need multi-currency support.  However, I find that products can only be priced in the home currency, We sell to the US and UK.  However, we maintain different price lists for each. 
                                                                                                              • Missing information data Zoho inventory

                                                                                                                there some missing data in Zoho inventory connection. pick list stock counts bin location we have requested it via mail and the support team doesn’t gove feedback. has anyone achieve to get these info or to ask other ya les
                                                                                                              • Calendar Events Issues

                                                                                                                Not able to view scheduled events on my calendar
                                                                                                              • Extensions 101 webinar series: Build, integrate, and monetize with extensions

                                                                                                                Attention developers! Are you ready to take your extension development skills to the next level? We're excited to bring back the Extensions 101 webinar series with an expanded lineup of Zoho products and an introduction to more platform features. Last
                                                                                                              • Custom Related List Inside Zoho Books

                                                                                                                Hello, We can create the Related list inside the zoho books by the deluge code, I am sharing the reference code Please have a look may be it will help you. //..........Get Org Details organizationID = organization.get("organization_id"); Recordid = cm_g_a_data.get("module_record_id");
                                                                                                              • Where are recordings stored?

                                                                                                                I have hosted a couple of test meeting, used the "record" button to start and stop the recording but I am unable to find where are those recordings saved?  Can anybody help? Thanks
                                                                                                              • Zoho Desk's integration with Microsoft PowerBI delivers advanced analytics insights

                                                                                                                Hello everyone, Gaining advanced insights through reports and dashboards is one of the critical requirements of every business. In addition to key metrics tracked in Zoho Desk, such as agent performance, SLA adherence, and ticket lifecycle, businesses
                                                                                                              • Create static subforms in Zoho CRM: streamline data entry with pre-defined values

                                                                                                                Last modified on (9 July, 2025): This feature was available in early access and is currently being rolled out to customers in phases. Currently available for users in the the AU, CA, and SA DCs. It will be enabled for the remaining DCs in the next couple
                                                                                                              • IMAP error message in Zoho mail

                                                                                                                I cannot send emails today. Everything fine for years until today. Get a message: "You are yet to enable IMAP for your account. Please contact your administrator". Does anyone know how to correct this?
                                                                                                              • IMAP stopped working today

                                                                                                                Hello! I've been a paid customer for more than 10 years, IMAP was always working fine. But today this is the error I've got on my iPhone: I've tried toggling the IMAP for my account (Mail -> Settings -> Mail accounts) off and on again, but that did not
                                                                                                              • Are custom portals accessible on the Zoho learn smartphone app?

                                                                                                                In other words, can users external to my organisation, once signed up, use the app in the same way as internal users? Thanks
                                                                                                              • Zoho Books/Inventory - Update Marketplace Sales Order via API

                                                                                                                Hi everyone, Does anyone know if there is a way to update Sales Orders created from a marketplace intigration (Shopify in this case) via API? I'm trying to cover a scenario where an order is changed on the Shopify end and the changes must be reflected
                                                                                                              • Conditional Layouts On Multi Select Field

                                                                                                                How we can use Conditional Layouts On Multi Select Field field? Please help.
                                                                                                              • Multiple columns in a form

                                                                                                                I am evaluating Zoho Creator. However, I am seeing almost no layout control on a form.  Just a basic 1 or 2 column format that is then imposed on the entire form.  That's not going to work for many, many real world cases. We need multiple columns per line, and we need each line/section to occupy a single column or be able to span the columns.   Someone please tell me that I'm missing something and the capability is actually there.  
                                                                                                              • Global search

                                                                                                                Hi! I think it would be great to have a global search that would give you results from all records of a database, no only for a single field of a single form as we have now. Thanks!
                                                                                                              • Any insights about API/v2? Having problem for a while.

                                                                                                                I don't know why it is throwing a 404 error, my report name is correct. Has someone had this issue and how you fix it?
                                                                                                              • Edit QR code with redirect to form

                                                                                                                Guten morgen, wir haben ein Formular Reklamation_erstellen. Dort soll ein QR Code erstellt werden, der im Lieferschein angezeigt wird. Beim Scannen auf dem soll das jeweilige Formular zum BEARBEITEN geöffnet werden. Leider bekomme ich es nur so hin, dass
                                                                                                              • Getting all the ingredients together for baking an app

                                                                                                                Good day everyone. After reading a lot of the help docs and watching videos, I now started on my app. To prevent hours and hours wasted on going down the wrong track, I would like some clarification on the following. But first some background: I have
                                                                                                              • Help Needed with Configuring ZC Microservice

                                                                                                                I'm attempting to create a simple microservice, but am running into problems with scope and auth. Using Custom API Builder, here's my setup: 1. Method: GET 2. Auth: OAuth2 3. User Scope: All users 4. Response: Standard 5. Function: A function that returns
                                                                                                              • Creator Simplified #10: Predefine Form Field Values and Make Them Read-Only for Users

                                                                                                                Hey Creators, Ready for this week's tip in the Creator Simplified series? Today, we will explore how to have read only fields in a form. Use Case: Assume a scenario where the default value for a Department field needs to be English Literature, but you
                                                                                                              • Zoho Mail : Email Outgoing Blocked

                                                                                                                I suddenly received the following message yesterday. I cannot send any mail. Please resolve as soon as possible, I cannot work without sending email. Dear User, We regret to inform you that your email outgoing has been blocked and you will not be able
                                                                                                              • Creator and Tables

                                                                                                                Good day. I am trying to create my first application. I have imported my data into Tables and am creating my app in Creator. I do not see my tables and cannot see how to write forms data to a table. Even the Workflow just uses the form. In one of the
                                                                                                              • customer Name and address details

                                                                                                                i created one application there is no customer details in that . how to add customer details and
                                                                                                              • Next Page