$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
  • Hi Ajay

        This is the code which i am using for executing an sql statement in the before save logic hook

    <>/custom/modules/Users/logic_hooks_class.php

    $hook_version = 1;

    $hook_array = array();

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

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

            //Processing index. For sorting the array.

            1,

            'before_save example',

            'custom/modules/Users/logic_hooks_class.php',

            'logic_hooks_class',

            'before_save_method'

        );

    In

    <>/custom/modules/Users/logic_hooks.php

    <?php

      if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class logic_hooks_class{

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

              global $db;

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

              }

    }

Children