and the LogicHooksClassTest.php at the same path: /var/www/html/SCRM/custom/modules/user_account :
<?php
class LogicHooksClassTest
{
function autoFillCustomField($bean, $event, $arguments)
{
$bean->customer_cui = $bean->customer_code_crs;
}
}
Both the fields customer_cui and customer_code_crs are defined as integers in user_account module.
SuiteCRM version is Version 7.14.3
Sugar Version 6.5.25 (Build 344)
I was not able to find any logging regarding the hook.
Best regards,
unfortunately is still not working. of course i repaired and built again, and i also cleared the browser cache after each new saving
it should be something very simple (my intention is to be able to fill in fields with some api values in the end…but it looks like i am not able to manage this ) I tried to make a print screen with all the relevant info.
Regards,
First, you should make sure that the file is getting picked up. You could add some code in the logic_hook.php file to leave some logging or write some file on the disk, so you could make sure it was executed.
Then, if the hook gets correctly defined in the hook array, the next step is to check if the function call happens: put some logging there at the beginning.
Only after you are sure of that, try changing the bean.
Hello,
I kept trying to do some logging but unfortunately i haven’t succeeded.
What i have done:
Given permissions to the files:
root@contractservicingprocessor:/var/www/html/SCRM/custom/modules/user_account# ls -l
total 12
-rw-r–r-- 1 www-data www-data 1691 Apr 15 11:51 LogicHooksClass.php
-rw-r–r-- 1 www-data www-data 657 Apr 15 14:32 LogicHooksClassTest.php
modified the hook as per below:
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(
1, // Sorting order, lower numbers are processed first
'Test AutoFill Custom Field', // Description of the hook for identification
'custom/modules/user_account/LogicHooksClassTest.php', // Path to the logic hook class file
'LogicHooksClassTest', // Name of the class containing the hook method
'autoFillCustomField' // Name of the method to be called
);
// Optional: Debugging line to check file loading
file_put_contents('custom/modules/user_account/logic_hook_loaded.log', "logic_hooks.php loaded at " . date('Y-m-d H:i:s') . "\n", FILE_APPEND);
modified the hook function as per below just to be sure everything is ok from the syntax pov (test1 field is a text field):
<?php
class LogicHooksClassTest
{
public function autoFillCustomField($bean, $event, $arguments)
{
// Basic logging to SuiteCRM log file to confirm execution
global $log;
$log->fatal("Hook executed: Entered autoFillCustomField method for bean ID: {$bean->id}");
// Simple operation for testing: updating a field with a static value
$bean->test1 = 'Test value set by logic hook'; // Ensure 'some_custom_field_c' exists in your module
// Optional: Direct PHP logging for troubleshooting
error_log("Hook executed for record {$bean->id} at " . date('Y-m-d H:i:s'));
}
}
the path for the hook and hook function is: /var/www/html/SCRM/custom/module/user_account (the installation directory is SCRM and the cusotm module’s folder is user_account)
There is still no logging neither at suitecrm level nor php…
if you’d have any other ideas i would very much like to hear them.
I left only the hook in the user_account folder as you suggested.
This is what i get in the suitecrm.log:
Mon Apr 15 21:17:50 2024 [3200500][1][DEBUG] Performing action: action_save MODULE: cprd_user_account Mon Apr 15 21:17:50 2024 [3200500][1][DEBUG] Hook called: cprd_user_account::before_save
Mon Apr 15 21:17:50 2024 [3200500][1][INFO] Query:INSERT INTO cprd_user_account (id,name,date_entered,date_modified,modified_user_id,created_by,deleted,customer_segment,customer_cui,customer_code_crs,test1,test2)
VALUES (‘7d8fdad5-b2af-906a-e880-661d6f77f9be’,‘’,‘2024-04-15 18:17:50’,‘2024-04-15 18:17:50’,‘1’,‘1’,0,‘Micro’,NULL,6,‘’,‘’)
It seems that the hook is called now but it doesn’t trigger the hook function.
There is no other log file written or updated.
What i noticed is that in the log the module is cprd_user_account which is the “package key_module name” and not the module name. This is also the name i see in the DB for the corresponding table.
i have one more question: the before_save hook is executing the logic from the hook function also in the UI before saving? In my case the value i have in the field should be completed real time in the UI?