I use SugarCRM and i try to make a Hook when someone save a opportunity.
This is the situation:
I have the column "Opportunity Amount" and i want to calculate the column "Montant %".
So i have add twoo ligne in the hook:
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1,'calcul montant heure','custom/modules/Opportunities/calcul.php','calcul','montant');
I add the class file:
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class calcul
{
var $module = "Opportunities";
function montant($bean, $event, $arguments)
{
$bean->Montant_perc = ($bean->amount_usdollar * $bean->Probability (%))/100;
}
}
?>
it does not work but I do not understand why?
thanks for your help
I think that you need to recheck the fields name that you are using in before_save logic hook method becuase it seems to me that you are using field labels instead of field names i.e i think
$bean->Probability (%)
should be
$bean->probability
and as the field saved in db is generally in small letters so you should also check that the field
$bean->Montant_perc
should be
$bean->montant_perc
After making these modification do a Quick Repair and then resave the Opportunity to trigger before_save logic hook