Sales commissions form a critical component of many sales organizations' compensation strategies, as they directly influence revenue generation and team motivation. When sales reps create quotes, they need immediate visibility into their potential earnings to make informed decisions during negotiations. Currently, they manually calculate their earnings for each quote, which can result in errors and inefficiencies—but not anymore!
A function-powered custom button can automatically calculate the total commission for a quote by using the commission rate data stored in the Products module, which calculates the commission for each line item within a quote, aggregates the total commission across all items, and automatically updates the final amount in a custom field in the Quotes module. This real-time visibility empowers sales reps to optimize their quote strategies while ensuring accurate commission tracking for management reporting. 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 scopes as detailed in the "Create Connection" section below. Learn more
- Add a Currency field in the Quotes module. This field will hold the total commission for the products associated with the quote. Learn more
- Create and link the button with the custom function, as detailed in the "Create a button" section below. Learn more
- Test the custom button in a sandbox before deploying it to your production environment. Learn more
Create a connection
The first step is to create a Zoho CRM connection in your account.
- Go to Setup > Developer Hub > Connections.
- Click Create Connection.
- Select Zoho CRM under Default Services.
- Specify a Connection Name.
You must enter this name in the code snippet below. - Select the following Scopes 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 a custom field
The next step is to add a currency field to the Quotes module.
- Navigate to Setup > Customization > Modules and Fields.
- Click the Quotes module to open the layout editor.
- Drag and drop the Currency field from the New Fields tray to the desired section of the layout.
- Name the currency field (e.g., "Total Commission"), define its properties as required, then click Done.
- Once you've finished, click Save and Close.
Create a button
The final step is to create a custom button that, when clicked, calculates the commission for each quoted product and updates the total in its custom currency field.
- Navigate to Setup > Customization > Modules and Fields > Quotes > Buttons > Create New Button.
- Provide a name for the button. For example: "Calculate Commission".
- 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.
- Select the profiles that can view this custom button.
- Click Save.
The code
resp = invokeurl
[
url :"https://www.zohoapis.com/crm/v8/Quotes/" + quoteId
type :GET
connection:"connectionname"
];
info resp;
soinfo = resp.get("data").get(0);
productDet = soinfo.get("Quoted_Items");
value = 0.0;
for each eachProd in productDet
{
qty = ifnull(eachProd.get("Quantity"),"0").toLong();
productId = ifnull(eachProd.get("Product_Name"),"").get("id");
proDetails = zoho.crm.getRecordById("Products",productId.toLong());
commission = ifnull(proDetails.get("Commission_Rate"),"0.0").toDecimal();
value = value + commission * qty;
}
params = Map();
params.put("Total_Commission",value);
dlist = List();
dlist.add(params);
dmp = Map();
dmp.put("data",dlist);
update = invokeurl
[
url :"https://www.zohoapis.com/crm/v8/Quotes/" + quoteId
type :PUT
parameters:dmp + ""
connection:"connectionname"
];
info dmp;
info update;
return "Success";Notes
- Replace "connectionname" with the name of the Zoho CRM connection.
- Make sure to use the accurate API names of the fields in the code snippet (e.g., "Commission Rate and Total Commission"). Learn more
- The code above is an example that serves to auto-compute sales commission for quoted products with varying commission rates. You can use this code for computing commissions in any other module, such as invoices, by modifying the module name and parameters.
Test the solution
- Navigate to Quotes > + Create Quote.
- On the Quote Details page, enter the required details, including Product Name and Quantity for the line items, then click Save.
Note: Ensure that the products entered in the line items have a pre-filled commission rate. - Click the button you added in the top-right corner.
The custom function will be triggered. - Check whether the Total Commission in the quote is correctly updated based on the commission rates of the selected products.
- Test with products that have different commission rates to ensure the calculation is accurate.
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