Hello everybody,
I’m a little bit confused about the documentation for the custom logic hooks.
I created a custom logic hook for the module “Accounts”. The logic hook should set a customer number for every new account.
At the table accounts_cstm I’ll have a field that called “customerno_c”.
Then I created the file “CustomerNo.php” at the directory “custom/Extension/modules/Accounts/Ext/LogicHooks”.
Content of the file “CustomerNo.php”:
<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(1, 'setStoredAccountsNumber', 'custom/modules/Accounts/SetAccountsNumber.php', 'SetAccountsNumber', 'setStoredAccountsNumber');
At the directory “custom/modules/Accounts/” I didn’t changed the file “logic_hooks.php”.
But I created the file “SetAccountsNumber.php”. The content is the following:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not a valid entry point');
class SetAccountsNumber
{
function SetStoredAccountsNumber(&$bean, $event, $arguments)
{
if(isset($GLOBALS['log'])){
$GLOBALS['log']->fatal('Creating new instance of hook class '.$hook_class.' with parameters');
}
$module=$bean->parent_type;
$record_id=$bean->parent_id;
$bean1 = BeanFactory::getBean($module, $record_id);
$tblname = $bean1->table_name;
$tblname_cstm = $tblname."_cstm";
$bean->db->query("UPDATE ".$tblname_cstm." SET customerno_c='XYZABC' WHERE id_c='".$bean1->id."'");
}
}
At the end I run “Quick Repair and Rebuild”.
But if I create a new account or update one, nothing happend with the field "customerno_c in database. Also there is no logentry in logfile from suitecrm.
What did I wrong?