Compute and update sales commission in Quotes

In most sales organizations, commissions are an integral part of the extrinsic rewards program, contributing significantly to the sales rep’s compensation package. Sales commission is usually calculated as a percentage of revenue generated by the sales rep. What if your sales team is enabled with an option to check their sales commission associated with each quote? The tip unravels just that.

Let's assume a case where a sales person gets a commission based on the quantity of products she/he sells. I'm sure you agree that this is an important practice in many companies. Internally, there must be records to know just how much commission the sales rep received. Zoho CRM tracks the commission associated with the sale of each product in ‘Commission Rate’, a standard field in the Products module. Using Functions, this information is pushed to the Quotes module. The commission associated with each line item of the quote is calculated and summed up to find the overall commission associated with that quote. The resultant value is then updated in a custom field in the Quotes module. Pretty convenient right?


Getting started with the function:

  • Go to Setup > Customization > Modules and Fields > Modules > Deals > Links and Buttons > + New Button.
  • Provide a name for the button. For example: "Create Quote from deal". Add a description(optional).
  • Select the placement of the button as View Page.
  • Select the action to be performed as "Writing function".
  • Copy the code given below.
  • 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.

The Code:


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;

 

Note:

  • The code is zoho.crm._getRecordById for Version 1.0 of APIs.
  • Change the "[field Id]" or "[module]" name to any other module or field name(Custom modules or fields) to fit your requirement.
  • Update the commission associated with each product in the Products module.
  • Create a custom field in Quotes module where the commission associated with the quote gets updated.
 

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!

Return to Tips