Welcome back folks!
In this week's custom functions series, we've picked a requirement that has often been asked by users!
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 Custom 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 custom 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?
Steps to add a custom function:
The script:
Code for Version 2.0 API:
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;
Note:
Do try this out and let me know how it worked. If you have questions, ask away. Share this with your team if you think they'll find this useful. See you all next week with another interesting custom function in this series. Until then!