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 person’s compensation package. Sales commission is usually calculated as a percentage of revenue generated by the sales person. What if your sales team is enabled with an option to check their sales commission associated with each quote? The first post in 'Automate using Functions' series 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 person 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:

  1. Go to Setup > Customization > Modules > Deals > Links and buttons > Create new button.
  2. Provide a name for the button. For example: "Create Quote from deal". Add a description(optional).
  3. Select the placement of the button as View page.
  4. Select the action to be performed as "Writing function".
  5. Copy the code given below.
  6. Click "Edit arguments".
  7. Enter the name as "potId" and select the value as "Potential Id".
  8. Click Save & Execute Script.
  9. Save the changes.
  10. Select the profiles who can view this button.
  11. ClickSave.
 

The Code:


	quoteIdStr = input.quoteId.toString();
	quoteMap = zoho.crm._getRecordById("Quotes", input.quoteId);
	productDet = ifnull(quoteMap.get("product"),"");
	productList = productDet.toJSONList();
	value = 0.0;
	for each eachProd in productList
	{
	eachProdDet = eachProd.toMap();
	qty = (ifnull(eachProdDet.get("Quantity"),"0")).toLong();
	productId = ifnull(eachProdDet.get("Product 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._updateRecord("Quotes", quoteIdStr, params);
	
	

 

Note:

  • The code is zoho.crm._getRecordById for Version 1.0 of APIs.
 

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