Hi All,
Iāve been trying to understand how to develop logic hooks for my SuiteCRM instance and was looking for some help. Iāve read several of the guides which have not made it any easier to understand. What Iām trying to achieve is the following.
Iāve created a custom module named Candidates. In this module I have fields named candidate_name and candidate_no and Iāve created a relationship one to many with the tasks module. In the task module Iāve created two custom fields named candidate_name_c and candidate_no_c and customised the my open tasks dashlet to display these two new fields.
What I want to do is when creating a task using the sub panel in the Candidates Module is to have the candidate_name_c and candidate_no_c within tasks to be populated with the data from candidate_name and candidate_no from the Candidates Module. This is so on the dashlet users can see the candidate name and number the task relates to.
Iāve then created a logic hook before_save_class.php in custom/modules/candidates/. The file is as follows
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class before_save_class
{
function before_save_method($bean, $event, $arguments)
{
//canidate field in Tasks is candidate_tasks
//We will use beans to fetch the related candidate details
$candidate = new Task();
$candidate->retrieve($bean->candidate_tasks);
//Set the values from Candidates into Tasks
// $bean is your current record being saved.
// $candidate is the related candidate.
$bean->candidate_name_c = $candidate->name;
$bean->candidate_no_c = $candidate->candidate_no;
//Same stuff in order to set other values
}
}
?>
After running a repair and trying to create a task and clicking save nothing happens. No task is created and no error shown. Checking the event logs I see the following entries
[Fri Sep 08 13:54:54.988730 2017] [:error] [pid 2628:tid 1968] [client 172.16.102.26:58713] PHP Fatal error: Cannot use [] for reading in C:\xampp\htdocs\suitecrm\custom\modules\Tasks\logic_hooks.php on line 2, referer: http://idweb01/suitecrm/index.php?action=ajaxui
[Fri Sep 08 13:57:32.180624 2017] [:error] [pid 2628:tid 1940] [client 172.16.102.26:58771] PHP Fatal error: Cannot use [] for reading in C:\xampp\htdocs\suitecrm\custom\modules\Tasks\logic_hooks.php on line 2, referer: http://idweb01/suitecrm/index.php?action=ajaxui
[Fri Sep 08 14:06:47.754984 2017] [:error] [pid 2628:tid 1960] [client 172.16.102.26:58926] PHP Fatal error: Cannot use [] for reading in C:\xampp\htdocs\suitecrm\custom\modules\Tasks\logic_hooks.php on line 2, referer: http://idweb01/suitecrm/index.php?action=ajaxui
Not sure what Iāve done wrong but any help would be appreciated
Please edit your post (or post again) this time putting all your code and logs inside the forumsā code tags. That way we can see which brackets you used and make sure the syntax is correct⦠the way it is now, the forums remove parts of what you postedā¦
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class before_save_class
{
function before_save_method($bean, $event, $arguments)
{
//canidate field in Tasks is candidate_tasks
//We will use beans to fetch the related candidate details
$candidate = new Task();
$candidate->retrieve($bean->candidate_tasks);
//Set the values from Candidates into Tasks
// $bean is your current record being saved.
// $candidate is the related candidate.
$bean->candidate_name_c = $candidate->name;
$bean->candidate_no_c = $candidate->candidate_no;
//Same stuff in order to set other values
}
}
?>
Not sure where Iām going wrong here or whether Iām referencing the wrong tables.
Iāve attached images of my setup along with my code.
\custom\modules\CAN_Candidate\before_save_class.php contains the following code
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class before_save_class
{
function before_save_method($bean, $event, $arguments)
{
//lets assume the candidate field in tasks is candidate_tasks
//We will use beans to fetch the related candidate's details
$candidate = new Task();
$candidate->retrieve($bean->can_candidate_tasks_c);
//Set the values from candidates into tasks
// $bean is your current record being saved.
// $candidate is the related candidate.
$bean->candidate_name_c = $candidate->name;
$bean->candidate_no_c = $candidate->candidate_no;
//Same stuff in order to set other values
}
}
?>
\custom\modules\Tasks\logic_hooks.php file contains the following code
<?php
$hook_version = 1;
$hook_array['before_save'][] = Array(
//Processing index. For sorting the array.
1,
//Label. A string value to identify the hook.
'before_save_candidate',
//The PHP file where your class is located.
'custom/modules/CAN_Candidate/before_save_class.php',
//The class the method is in.
'before_save_class',
//The method to call.
'before_save_method'
);
?>
You can see on the attached Capture1.png the tasks subpanel should has two custom fields that should be filled with Candidate Name and Candidate No from the Canidate module but this is not happening.
Let me know if thereās anything else I can provide to help with fixing the issue.