$GLOBALS["db"]->query()  not working in before save logic hook

Hi

  I want to execute an sql statement in the before save logic hook.

I have tried

$GLOBALS['db']->query("UPDATE users SET description='test' WHERE id='27283e5a-8f34-b846-367a-561fbbb4cb54'");

$db = DBManagerFactory::getInstance();

$res = $db->query("UPDATE users SET description='test' WHERE id='27283e5a-8f34-b846-367a-561fbbb4cb54'");

But it is not working.Shijin Krishna@

Parents Reply
  • Hello Anand Chitikela,

    I tested below code in contacts module sugar ent 7.6.1.0.It is working for me.

    /crm/custom/Extension/modules/Contacts/Ext/LogicHooks/logic_hooks.php

    <?php

        $hook_version = 1;

        $hook_array = array();

        $hook_array['before_save'] = array();

        $hook_array['before_save'][] = array(

            1,

            'test',

            'custom/modules/Contacts/customLogicHook.php',

            'TestClass',

            'TestFunction'

        );

    ?>

    /crm/custom/modules/Contacts/customLogicHook.php

    <?php

    if(!defined('sugarEntry')) die('Not a valid entry point');

        class TestClass

        {

            function TestFunction($bean, $event, $arguments)

            {

                $bean->phone_mobile='556677';

                $GLOBALS['log']->fatal("before save logic hook gets called");       

            }

        }

    ?>

Children