We will cover all that you need to know in order to calculate the total of an opportunity after a discount.
You will need the following fields:
- Opportunity Amount, Field Type: Currency
- Discount %, Field Type: Percentage
You can use the names that best suit your organization for these fields. You will just need to replace their names in the code snippet below.
If you want to learn how to create Fields, please visit the following tutorial:
Fields
Give a meaningful name to your field and enter a description, although optional is recommended to let your users know that this field is a calculated one. The field type should be set to 'Currency' and the 'Calculated' box enabled in order to display the calculation section. Then copy & paste the code below:
(function(deal_fa){
return (deal_fa.amount * deal_fa.discount);
}(deal));
If your fields have different names, you would need to replace the bold parts with the right field name. You should also make sure that your app system name matches what you have in your script. You can find this in 'App Configuration' towards the bottom of the screen under 'System Information'.
Once you are done, click the Save button.
This calculation will happen when the information on the Amount and Discount fields have information. If one of the two fields is missing, then the Discount total won't be calculated.
To avoid this from happening make both the Amount and the Discount fields 'Required'.
Since we provided the amount and discount % in the Opportunity shown in the image below, the calculation was done successfully and we can see the Total of the Opportunity after the discount.