Logical hook displaying some information from parent record throws error

I have an instance of SugarCRM 6.5 CE and one of the requirements I have to fulfill is to display some information - contact phone number, contact email address - parent record in a related task / activity record.

Everything I've found so far has pointed to creating a boolean hook to pull contact information from the parent record (Contacts) and display them in the custom fields of the child record (Tasks).

Following some instructions and examples, I came up with the following as described below.

In the section "custom / modules / Tasks" I create a file called "logic_hooks.php"

<?php// $Id$
$hook_version = 1;
$hook_array = Array();

// debug
$GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
$GLOBALS['log']->debug("Task: logic hook invoked"); 

// position, file, function
$hook_array['after_retrieve'] = Array();
$hook_array['after_retrieve'][] = Array('1', 'contact_info', 'custom/modules/Tasks/hooks/contact_info.php','contact_info_class', 'contact_info_method');
?>

      

and under "custom / modules / Tasks / hooks" I create a file called "contact_info.phplogic_hooks.php"

<?php
class contact_info_class {
    // retrieve contact information from parent record
    function contact_info_method($bean, $event, $arguments) {
        // debug
        $GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
        $GLOBALS['log']->debug("Tasks: contact_info_method called for event ".$event . "(BeanID: " . $bean->id . ")");

        // fetch data
        if ($bean->fetched_row['id'] != $bean->id) {
            // load Task
            //$bean = BeanFactory::getBean('Tasks', $id);

            // check if relationship is loaded
            //if ($bean->load_relationship('contact_tasks_parent'))
            if ($bean->load_relationship('contact_tasks')) {
                // fetch related beans 
                //$relatedBeans = $bean->contact_tasks_parent->getBeans();
                $relatedBeans = $bean->contact_tasks->getBeans();

                $parentBean = false;
                if (!empty($relatedBeans)) {
                    // order the results
                    reset($relatedBeans);

                    // first record in the list is the parent
                    $parentBean = current($relatedBeans);

                    // retrieve data from parent bean
                    $bean->contact_phone_c = $parentBean->phone_work
                    $bean->contact_primary_email_c = $parentBean->email1
                }
            }
        }
    } // contact_info_method
} // contact_info_class
?>

      

With this hook, I can create new tasks without any problem, but when I open an existing one I get a message reading

An error occurred while processing your request. Please try again later.

Being completely new to SugarCRM (around 6.5.20 CE this is my case), I have no idea what is going wrong here.

I also can't seem to find any debug messages that need to be written somewhere.

- Sil68

+3


source to share


1 answer


The "contact_info.phplogic_hooks.php" file must be located in the same folder as logic_hooks.php (custom / modules / <module-name>). And there is no need to call it that way (in fact, I think it might cause problems). Try to simply call it contact_info.php and change the path specified in the logic_hooks.php file to custom / modules / Tasks / contact_info.php.

As for where you can find the error log, if you are using apache for your webserver (as you did not specify) for linux / OS X, the error log is at

/var/log/apache2/error.log

or

/ var / log / apache2 / error_log



In the windows it will be

'C: \ Program Files \ Apache Software Foundation \ Apache2.2 \ logs.

Now that you know where the error log is, you can put

error_log('some helpful message');

      

inside your contact_info.php file and see what messages (if any) are sent to the error log. This might tell you if it even triggers the logical hook, and if so, how far it goes through the logical hook

0


source







All Articles