Mahi Chopra
Mahi Chopra

Reputation: 103

How to add two numbers in sugar crm

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

Answers (1)

The code looks correct.

Some common "mistakes" when custom logic hooks are not working:

  • Make sure, the custom logic hook has the correct name (LogicHookMath.php)
  • Make sure, that the $bean variable is prefixed with &, so the variable is passed as a reference
  • Make sure the logic_hooks.php and the LogicHookMath.php files are readable by the web server user
  • The entire custom directory should also be writeable for the web server user

If 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

Related Questions