In sales operations, tracking the aggregate values of line items within quotes is crucial for accurate financial reporting and decision-making. Sales teams often need quick visibility into total quantities ordered, cumulative discounts offered, and tax implications across all products in a quote. Manually calculating these values for each quote revision can be time-consuming and error-prone, and can potentially lead to pricing mistakes or delayed quote approvals. But now there's a better solution.
You can automatically calculate and update three critical metrics at the quote level—the total quantity of all products, the sum of line-item discounts, and the aggregate tax amounts—all at the click of a button. All you need to do is create a custom function and connect it to a button that updates these totals in their respective fields within a quote record.
Your sales operations team can instantly see these totals updated whenever quote line items are modified to ensure accurate quote summaries for faster approvals and improved financial visibility. Sound interesting? Read on to learn more.
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 and buttons.
- Users with the Manage Sandbox permission 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 two custom Currency fields and one Number field to the Quotes module. These fields will hold the total tax, total discount, and total quantity for the quote. Learn more
- Create and link a button with a custom function, as detailed in the "Create a button" section below. Learn more
- Test the solution 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.
- Go 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 authorization for the scope requested by the client.
Add custom fields
Next, add the custom currency and number fields to the Quotes module.
- Navigate to Setup > Customization > Modules and Fields, then select the Quotes module to open the layout editor.
- In the layout editor, do the following:
- Drag and drop the Number field, name it (e.g., "Total Quantity"), define its properties, and click Done.
- Drag and drop the Currency field, name it (e.g., "Total Discount at line item level"), define its properties, and click Done.
- Drag and drop another Currency field, name it (e.g., "Total Tax at line item level"), define its properties, and click Done.
- Once you've finished, click Save and Close.
Create a button
Next, create a custom button linked to a function in the Quotes module.
- Navigate to Setup > Customization > Modules and Fields > Quotes > Buttons > Create New Button.
- Provide a name for the button. For example: "Sum line items field values".
- Add a description (optional).
- Set the action to be performed as Function.
- Select the button's page and position as "In Record" and "Details," respectively.
- Choose the layouts where you want the button to be placed.
- Click Choose to configure a function and select Write your own.
- Provide names for both the display and the function, then click Create.
- On the Deluge Script Editor, do the following:
- Copy and paste the code provided below.
- Click Edit Arguments.
- Enter the name as quoteId, select the value as Quotes - Quote Id, then click Save.
- Save the function.
- Turn on button accessibility for CRM Users.
- Select the profiles that can view this custom button.
- Click Save.
The code
resp = invokeurl
[
url :"https://www.zohoapis.com/crm/v7/Quotes/" + quoteId
type :GET
connection:"connectionname"
];
info resp;
soinfo = resp.get("data").get(0);
product_list = soinfo.get("Quoted_Items");
plist = List();
linetaxes = 0.0;
linediscount = 0.0;
value = 0;
for each eachProd in product_list
{
linetax = ifnull(eachProd.get("Tax"),"0.0").toDecimal();
linetaxes = linetaxes + linetax;
linedis = ifnull(eachProd.get("Discount"),"0.0").toDecimal();
info linedis;
linediscount = linediscount + linedis;
qty = ifnull(eachProd.get("quantity"),"0").toLong();
value = value + qty;
}
params = Map();
params.put("Total_Quantity",value);
params.put("Total_Discount_at_line_item_level",linediscount);
params.put("Total_Tax_at_line_item_level",linetaxes);
dlist = List();
dlist.add(params);
dmp = Map();
dmp.put("data",dlist);
update = invokeurl
[
url :"https://www.zohoapis.com/crm/v7/Quotes/" + quoteId
type :PUT
parameters:dmp + ""
connection:"connectionname"
];
info dmp;
info update;
return "Quote totals updated successfully";Notes
- Make sure to use accurate API names for their corresponding fields (e.g., "Total Quantity") in the code snippet. Learn more
- Replace "connectionname" with the name of the connection you specified when creating it (see the "Create a connection" section above).
- Change the URL endpoint to match your account's data center. For example, https://www.zohoapis.in/... for India.
- You can add this function to a workflow rule that triggers upon creating or updating a quote.
- The script above automatically calculates and updates key totals for a quote based on its line items at the click of a button. You can use this code for other modules by modifying the module name, field names, and relevant parameters to suit your requirements.
Tip
- Configure and test the solution in a sandbox to ensure that further development doesn't disrupt your production environment.
Test the solution
- Navigate to the Quotes module.
- Create a new quote or select an existing one with multiple line items.
- Note the current values for quantity, discount, and tax for each line item.
- Click the button you added in the top-right corner.
The custom function will be triggered. - Check whether the custom fields in the quote are updated with the correct totals:
- Total Quantity should equal the sum of all line item quantities.
- Total Discount at Line Item Level should equal the sum of all discounts.
- Total Tax at Line Item Level should equal the sum of all taxes.
- Modify the line items in the quote, then click the button again to ensure the updates work correctly.
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
- ModuleQuotes
- Trigger PointCustom Button
- EditionEnterprise and above
- ComplexityMedium
- Implementation Time30 minutes

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