3

I've got an hosted instance of SugarCRM 6.5 CE, and one of the requirements I have to fulfil is to display some information--contact phone number, contact email address--of the parent record in an associated task/activity record.

All I found so far was pointing towards the creation of a logic hook for pulling the contact information from the parent record (Contacts) and display these in custom fields in the child record (Tasks).

Following some instructions and examples found I came up with the following as outlined below.

Under "custom/modules/Tasks" I've 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've 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 in place I can create new tasks without any problem at all, but when opening up an existing one, I'm receiving a message, reading

There was an error processing your request, please try again at a later time.

Being completely new to SugarCRM (btw. 6.5.20 CE it is I'm dealing with), I've got not the faintest idea as what is going wrong here.

I also cannot find any of the debug messages which are supposed to be written somewhere to.

--Sil68

user4338
  • 173
  • 1
  • 12

1 Answers1

0

The "contact_info.phplogic_hooks.php" file should be in the same folder as logic_hooks.php (custom/modules/< module-name>). And there's no need to name it that way (in fact I think it might cause problems). Try naming it just contact_info.php and changing the path given in the logic_hooks.php file to custom/modules/Tasks/contact_info.php.

As for where you can find the error log, assuming you're using apache for your web server (since you didn't specify) for linux/OS X, the error log is located at

/var/log/apache2/error.log

or

/var/log/apache2/error_log

In windows it'll be in

'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 which messages (if any) get sent to the error log. This can tell you if it even starts the logic hook and if so, how far it gets through the logic hook

StephanieS
  • 423
  • 4
  • 12