Compute sales commissions for deals

Automatically calculate and update sales commissions for deals with accuracy and ease of modification.

It is common to use formula fields to calculate sales commissions based on both the amount and percentage. You can determine the commission figure by multiplying the amount and percentage values (100*0.2), but this method can lead to headaches. For example, suppose the commission percentage or formula is updated later, the existing records will not be affected by the change, causing incorrect commission amounts in several records.

For this reason, we recommend using custom functions to calculate sales commissions. Using a custom function allows you to modify the formula by assigning the appropriate values, including the percentage. Moreover, you can update the commission amount for multiple records at once.

This solution provides a custom function that aids in calculating sales commissions for deal records. To use it, create the function and connect it to a workflow rule that triggers upon updating the amount field in a deal record.

Permissions and availability

  • Users with the Modules Customization permission can add custom fields.
  • Users with the Manage Automation permission can create and update workflow rules.
  • Users with the Manage Extensibility permission can create custom functions.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Add a Percent field and a Currency field in the Deals module. The percent field will hold the commission percentage, while you can use the currency field to record the commission amount computed based on the percentage. Learn more
  • Create a workflow rule for the Deals module that triggers every time a deal's amount is edited. Learn more
  • Write a custom Deluge function and link it up with the workflow rule. Learn more
  • Test the workflow rule in a sandbox before deploying it to your production environment. Learn more

Add custom fields

The first step is adding the custom percentage and currency fields to the Deals module.

  1. Navigate to Setup > Customization > Modules and Fields.
  2. Click the Deals module to open the layout editor, and do the following:
    1. Drag and drop the Percent field from the New Fields tray to the desired section of the layout.
    2. Name the percent field (e.g. "Commission Percentage") and define its properties as required.
    3. Drag and drop the Currency field from the New Fields tray to the desired location on the layout.
    4. Name the currency field (e.g. "Commission Amount") and define its properties as required.
  3. Once you have finished, click Save and Close.
Add Custom Fields

Create a workflow rule

  1. Navigate to Setup > Workflow Rules > +Create Rule.
  2. Select Deals from the module dropdown list.
  3. Provide a name for the rule. For example: "Calculate Sales Commission". 
  4. Add a description (optional), then click Next.
  5. In the Execute this workflow rule based on section, do the following:
    1. Choose Record Action, then select Edit from the dropdown.
    2. Check the box for Repeat this workflow whenever a Deal is edited.
    3. Choose Specific field(s) gets modified from the drop-down, then enter the condition "When <Amount> is modified to <any value>."
    4. Click Next.
  6. In the Which deals would you like to apply the rule to? section, specify the condition as "<Commission Percentage> <is not empty>" and click Next.
  7. Under Instant Actions, select Function and Write your own.
  8. Provide a name and description, if necessary, for the function.
  9. On the Deluge Script Editor, do the following:
    1. Copy and paste the code given below.
    2. Click Edit Arguments.
    3. Choose Deals - Deal Id, name it dealId, then click Save.
    4. Click Save & Execute Script.
  10. Click Save on the workflow rule page.

The code

Code Copied
//get amount field
salesAmount = zoho.crm.getRecordById("Deals",dealId).get("Amount");
info salesAmount;
//get commission percentage
commPerc = zoho.crm.getRecordById("Deals",dealId).get("Commission_Percentage") / 100;
info commPerc;
//calculate commission amount
commAmount = salesAmount * commPerc;
info commAmount;
//update the commission amount field
mp = Map();
mp.put("Commission_Amount",commAmount);
updateComm = zoho.crm.updateRecord("Deals",dealId,mp);
info updateComm;

Notes

  • Make sure to use the accurate API names of the custom fields in the code snippet (e.g., "Commission Amount and Commission Percentage"). Learn more
  • The code above is an example to auto-compute sales commission for deals. You can use this code for any other module, such as contacts, by modifying the module name and parameters.

Test the solution

  1. Navigate to the Deals module. 
  2. Open a deal record to view its details. 
  3. On the Deal Details page, enter (or edit) the deal's amount and commission percentage in their respective fields, and click Save
    The workflow rule will be triggered. 
  4. Check whether the commission amount gets updated according to the deals' amount and commission percentage.

Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.

More info

  • ModuleDeals
  • Trigger PointWorkflow Rule
  • EditionEnterprise and above
  • ComplexityMedium
  • Implementation Time30 minutes

Features used in the solution

Custom FieldWorkflow RuleDeluge ScriptSandbox
Story Image

Looking for a custom solution?

Contact us, we will help enhance your productivity at lightning speed.

SUBMIT REQUEST

Developers: Share your solution with our community!