Reputation: 103
I made module addition and in this made three fields amount1_c
, amount2_c
and total_amount_c
to add the two numbers and display the result in the third field. I done coding in the logic looks here is my code
<?
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1,'calculate_field', 'custom/modules/cases/LogicHookMath.php','LogicHookMath', 'calculate_field');
?>
and made one more file logic hook math. here is my code for
<?php
class LogicHookMath {
function calculate_field(&$bean, $event, $arguments) {
$field1 = $bean->amount1_c;
$field2 = $bean->amount2_c;
$field3 = $field1 + $field2;
$bean->amount_total_c = $field3;
}
}
?>
but still i did not get any result. Please help me out for this.
Upvotes: 2
Views: 498
Reputation: 1464
The code looks correct.
Some common "mistakes" when custom logic hooks are not working:
LogicHookMath.php
)$bean
variable is prefixed with &
, so the variable is passed as a referencelogic_hooks.php
and the LogicHookMath.php
files are readable by the web server userIf the above does not help, try logging the progress to the sugarcrm.log using $GLOBALS['log']->info( "Value 3: ". $field3);
in the custom logic hook.
Upvotes: 1