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:
- Go to Setup > Customization > Modules > Deals > Links and buttons > Create 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 "potId" and select the value as "Potential Id".
- Click Save & Execute Script.
- Save the changes.
- Select the profiles who can view this button.
- Click Save.
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);
- 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!