AnsweredAssumed Answered

after_relationship_add logic hook not retrieving related bean

Question asked by Francesca Shiekh on May 4, 2015
Latest reply on May 7, 2015 by Francesca Shiekh
On Cases I have an after_relationship_add logic hook which should check if we're relating the Case (bean) to an Email (related_module/related_id) and if certain conditions on the email bean are met do some stuff...

The problem is that the email bean is not retrieved.


               

   function update_on_relationship ($bean,$event,$arguments){

 

        global $current_user;

 

        require_once('custom/entry_points/Cases/saveCaseAttachments.php');

 

        $GLOBALS['log']->fatal("Arguments: " . print_r($arguments, true));

 

        $today = TimeDate::getInstance()->nowDb();

 

        if ($arguments['related_module'] =='Emails'){

 

                $e = BeanFactory::retrieveBean('Emails', $arguments['related_id']);

 

                $GLOBALS['log']->fatal("Bean: " . $bean->id . " Email: " . $e->id);

 

                //save any case attachments and link them to the case

 

                if(!empty($bean->id) && !empty($e->id)){

                   <do some stuff>

                }

        }

}


The log output from the code above looks like this:

from $GLOBALS['log']->fatal("Arguments: " . print_r($arguments, true));

Mon May  4 09:52:03 2015 [31136][2053ed63-d2dc-52e8-0049-4ddab9fc33f1][FATAL] Arguments: Array

 

(

 

    [id] => 9f0dc37b-cbe0-705a-78ee-55429008d96f

 

    [related_id] => 79207851-43c0-6d55-fca6-554787ef99e6

 

    [name] => testnb

 

    [related_name] => RE: [CASE:2685903] testnb 

 

    [module] => Cases

 

    [related_module] => Emails

 

    [link] => emails

 

    [relationship] => emails_cases_rel

 

)

 


from $GLOBALS['log']->fatal("Bean: " . $bean->id . " Email: " . $e->id);

 

Mon May  4 09:52:03 2015 [31136][2053ed63-d2dc-52e8-0049-4ddab9fc33f1][FATAL] 

Bean: 9f0dc37b-cbe0-705a-78ee-55429008d96f Email: 


Notice the Email Id is not available, therefore nothing else happens.

I don't understand why 

  $e = BeanFactory::retrieveBean('Emails', $arguments['related_id']);

does not retrieve the bean.

In the console the error is:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

https://<mysugar>/rest/v10/Mail 

               

But the email goes out just fine.

I suspect the inability to retrieve the Email bean is related to the failure of the Mail API.


Any thoughts?

Thanks,

FrancescaS

Outcomes