AnsweredAssumed Answered

Logic hook executes correctly for all actions except for creating from quick create

Question asked by Jaume Albaigès on Dec 3, 2014
Latest reply on Jul 27, 2015 by jihed jihed
Hello,

I have written some code for after_save and after_delete logic hooks in a custom module, in order to update a calculated field in a related module.

The question is that the code is properly executed when I create a new record from the editview, when I edit a record and when I delete a record... but it isn't when I create a new record from quickcreateview.

I know the logic hook is triggered in all cases because I write it in Sugar's log.

Here is my code:

class my_class
{
    public function my_function(&$bean, $event, $arguments)
    {
        $GLOBALS['log']->fatal("The event is: ".$event);

        if ($event == 'after_delete') {
            // Retrieve related record id
            $db =  DBManagerFactory::getInstance();
            $query = "SELECT my_related_id FROM relation_table
                        WHERE my_id = '".$arguments['id']."'";
            $result = $db->query($query, true);
            $row = $db->fetchByAssoc($result);
            $related_id = $row['my_related_id'];
        } else
            $related_id = $bean->my_related_id;

        $bean->db->query("UPDATE my_related_module SET my_calculated_field = my_value WHERE id_c = '{$related_id}'");
     }
}

So, as I said, the code is properly executed in all cases, except when I create a record from a subpanel in the related module. In that case, the last query seems not to be thrown, but no error shows nor in the screen neither in the log. When everything is fine that query is also logged by SugarCRM itself. In quick creation there is nothing in the log. Quite strange...

Any ideas? Thank you very much!

Outcomes