I am using Version 6.5.16 (Build 1082) of sugarcrm, I created 2 fields Points redeemed and Accumulated points. I would want to create another field balance point (Accumulated points-points redeemed), may I know how do I use the calculated field to calculate the balance point which will generate automatically when i key in point redeem and accumulated point?
3 Answers
click the "calculated value" checkbox for the field definition in Studio, edit the formula for the calculated field
subtract($accumulated_points_c,$redeemed_points_c)
(change the field names to match yours)

- 1,676
- 3
- 16
- 26
-
i am using the community edition hence i do not have the "calculated value" checkbox, may I know how to I code from scratch? Thanks – user3065807 Jan 22 '14 at 07:29
Without Sugar Logic you'll need to create JavaScript on the page to do this. See this page for adding JavaScript to views: https://www.atcoresystems.com/blog/adding-custom-javascript-to-a-sugarcrm-view
If you can adjust your requirement and do this calculation upon saving the record instead of doing it live on the page, you can use a logic hook. I find these to be much cleaner and easier. Create your logic file:
<?php
// custom/modules/MyModule/calc_balance_points.php
class calc_balance_point{
function calc_balance_point(&$bean,$event,$args){
$bean->balance_point_c = $bean->accumulated_points_c - $bean->redeemed_points_c;
}
}
Then adjust your logic hook definition to include it. This file likely already exists, so add this reference to the before_save hooks
<?php
// custom/modules/MyModule/logic_hooks.php
$hook_array = Array();
$hook_array['before_save'] = Array();
$hook_array['before_save'] = Array(1,'Calculate Points Balance','custom/modules/MyModule/calc_balance_points.php','calc_balance_point','calc_balance_point');

- 1,682
- 10
- 17
Also I found a good article about adding custom calculated fields. http://forums.sugarcrm.com/attachments/f3/9793d1361300845-calculated-field-sugarcrm-ce-customagingfield.pdf
From this forum discussion http://forums.sugarcrm.com/f3/calculated-field-sugarcrm-ce-85291/

- 271
- 3
- 2