
Originally Posted by
infamousse
This seems to be something of a necessity I wonder why this was not implemented into the module and fields sections of the admin panel. Would be a useful tool for just about everyone. Well going to continue my search for an answer that suits me.
This is one of the features targeted to version 6.0.
The sample logic hook to accomplish this feature:
custom/modules/Opportunities/logic_hooks.php
PHP Code:
<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1, 'calculate_field', 'custom/modules/Opportunities/OpportunityLogicHook.php','OpportunityLogicHook', 'calculate_field');
?>
custom/modules/Opportunities/OpportunityLogicHook.php
PHP Code:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class OpportunityLogicHook {
function calculate_field(&$focus, $event, $arguments) {
// andopes comment: for float numbers it is necessary to unformat them to avoid wrong calculation
require_once('modules/Currencies/Currency.php');
$field1 = unformat_number($focus->field1);
$field2 = unformat_number($focus->field2);
$field3 = unformat_number($focus->field3);
$field4 = $field1 + $field2 + $field3;
$focus->field4 = format_number($field4);
}
}
?>
Regards
Bookmarks