Join The Community Sign Up For Club Zenatta

Article Read Time:

3 Min

Search
Search
Stay Connected

Calculating Sales Commissions with Custom Functions in Zoho CRM

In all but the most badly-run sales departments, the commission is based on how much stuff a salesperson sells. However, it’s not always that straightforward: sometimes commissions vary based on products, with incentives to sell particular packages and services paid out in the form of higher commissions. A simple percentage calculation doesn’t typically cut it. To calculate your sales commissions instantly and accurately, we can build a commissions custom function in Zoho CRM. In this example, we will take data from your Quotes and calculate the commission based on the number of items sold.

We will build a custom button to trigger our custom function, which will run the code we provide on the parameters we specify. Zoho CRM uses a deeply customizable framework, so lots of decisions are left up to you. If you have a bit of programming or scripting experience, you’ll feel much more at home writing your own functions. If you want to try to wing it, look at our crash course in writing functions below.

Creating the Commissions Custom Function and Button

  • Log into your Zoho CRM account.
  • Navigate to Setup > Customization > Modules and Fields > Modules > Deals > Links and Buttons > + New Button.
  • Give the button a helpful name and an optional explanatory description.
  • Set the placement of the button on the record using View Page.
  • Set the action to Writing function.
  • Insert your commission calculation code. For example, you can use Zoho’s formula below (drawn from their library of function examples) which calculates the commission based on the number of specific items.
  • Click “Edit Arguments“.
  • Enter the name as “quoteId” and select the value as “Quote Id“.
  • Click Save & Execute Script.
  • Save the changes.
  • Select the profiles who can view this button.
  • Click Save.
quoteMap = zoho.crm.getRecordById("Quotes", input.quoteId.toLong()); 
productDet = ifnull(quoteMap.get("Product_Details"),""); 
value = 0.0; 
for each eachProd in productDet 
{ 
qty = (ifnull(eachProd.get("quantity"),"0")).toLong(); 
productId = ifnull(eachProd.get("product"),"").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); 
updateResp = zoho.crm.update("Quotes", quoteId.toLong(), params); 
info params;
info updateResp;

Writing Your Own Custom Functions

The function above if modified can calculate based on the total price of each product, rather than the total number of products sold. Instead of using eachProd.get(“quantity”), use eachProd.get(“list_price”) instead (making appropriate adjustments throughout) and use that in your final calculations. You can also build your own functions from the ground up using Zoho’s scripting language, Deluge.

A website banner with the AZAAZ logo and a description for when the episodes air on the youtube channel

To build a function like the one we’ve shown above, try to reflect the following pattern.

  1. Gather the information required to make the calculation.
  2. Execute the operations as needed by your requirements.
  3. Display the result of the calculation in the appropriate place and at the appropriate time.

Much as with a mathematical equation, your output values will always be based on your input values. This is the foundational metaphor for all programmatic behavior: what you put into the program changes what you get out of the program. The data we “put into” the program is more properly called the “arguments” of the program. What we “get out of” the program is our desired output: in this case, a calculation of the sales commission on a specific quote.

To calculate a commission, first, our arguments pull data from Zoho CRM records (step 1). Then, the code processes that data mathematically (step 2). Finally, outputs are displayed on-screen (step 3).

With that conceptual framework in mind, you only need to translate your basic systematic approach into the Deluge programming language used by Zoho. Of course, that can be a rather tall order for someone without programming experience. Try out this Deluge tutorial to see if you can get a handle on it, or jump head first into Deluge’s documentation. If it doesn’t come together, remember that we’re always here to help.

Check out our other Zoho CRM resources to learn more about customizing your system!

Billy Bates

Senior Web Developer

Billy is a Wordpress Developer with an eye for design. His knowledge will help our company website and client sites meet their goals. Billy and his young family have just moved to Ashland Oregon, and are looking forward to exploring the area’s amazing beer, wine, and food. He also has a passion for synthesizers and drum machines.

Lucas Sant'Anna

Consultant

With a background in Operations Research and Data Analysis, Lucas is a Brazilian programmer that likes to get stuff done quickly and reliably. In previous jobs, he implemented industrial job scheduling, fleet management and detailed long-haul route optimization – among other data-driven processes – to reach objectives of increased profit and reduced wasted resources. His goal is to make Zoho fully automated and with more meaningful data for spot-on decisions.

.

.