Results 1 to 4 of 4

Thread: Execute Stored Procedure (msssql) from logic hook

  1. #1
    richarddixonfl is offline Sugar Community Member
    Join Date
    Mar 2008
    Posts
    10

    Default Execute Stored Procedure (msssql) from logic hook

    I am trying to execute a stored procedure from a logic hook in order to be able to set a field in CRM based on some criteria that may change from time to time. The best way we saw fit was to call the stored procedure from the logic hook, pass it the ID Guid and then modify the fields on the database backend via the stored procedure.

    So far I have modified the /custom/modules/phones/logic_hook.php to look like this:

    <?php
    // Do not store anything in this file that is not part of the array or the hook version. This file will
    // be automatically rebuilt in the future.
    $hook_version = 1;
    $hook_array = Array();
    // position, file, function
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1, 'workflow', 'include/workflow/WorkFlowHandler.php','WorkFlowHandler', 'WorkFlowHandler');
    $hook_array['after_save'][] = Array(2, void, 'custom/modules/phone_Phones/phones_cstm.php', 'Phones_cstm', 'phone_after_save_1');
    ?>

    and the custom logic hook file, /custom/modules/phones/phones_cstm.php:

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

    class Phones_cstm
    {
    function phone_after_save_1()
    {
    //sleep(5);
    global $currentModule;

    //$query = "EXEC sp_phoneSaveHandler '$this->id';";
    $query = "exec sp_phoneSaveHandler '35D9FD03-C09D-493A-9A3D-D3D8F3FF0485';";
    $GLOBALS['log']->fatal($query);
    $result = $bean->db->query($query, true);
    //$db->query($query, true);

    }
    }

    ?>

    I have tried all sorts of things and all I get upon save is this:

    (the values from the page, then below

    Fatal error: Call to a member function query() on a non-object in E:\SugarCRM\custom\modules\phone_Phones\phones_cst m.php on line 14

    and in the log:
    04/28/11 14:18:05 [916][4eeb5a12-9668-6122-189f-47bb36dd9632][FATAL] exec sp_phoneSaveHandler '35D9FD03-C09D-493A-9A3D-D3D8F3FF0485';

    any quick solutions on how to do this correctly??

  2. #2
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: Execute Stored Procedure (msssql) from logic hook

    Try using the global db var:

    PHP Code:
    global $db;

    $db->query(....); 

  3. #3
    Angel's Avatar
    Angel is offline Sugar Community Member
    Join Date
    Jul 2005
    Location
    Los Angeles
    Posts
    4,813

    Default Re: Execute Stored Procedure (msssql) from logic hook

    Have you verified that the SP is stored within the Sugar database, as opposed to master (or other database)?

    Also, what happens if you try to execute SELECT @@version as your query?
    Regards,

    Angel Magaņa
    Co-Author: Implementing SugarCRM 5.x (Packt Publishing -- Sept. 2010)
    Blog: http://cheleguanaco.blogspot.com.
    Twitter: @cheleguanaco.

    ________
    | Projects: |_____________________________________
    |
    | CandyWrapper (.NET Wrapper for SugarCRM SOAP API). Source now available on GitHub!
    | GoldMine to SugarCRM Express Conversion. Latest: 1.0.1.7 (Nov. 3, 2009)
    | CRM SkyDialer (Skype Integration). Latest: 1.0.2 (Feb. 17, 2010)
    | Round Robin Leads Assignment
    | Phone Number Formatter
    | CaseTwit (Twitter Integration)
    ______________________________________________

  4. #4
    richarddixonfl is offline Sugar Community Member
    Join Date
    Mar 2008
    Posts
    10

    Default Re: Execute Stored Procedure (msssql) from logic hook

    @eggsurplus,

    Your solution worked perfectly.

    To answer Angel, the Stored procedure is in the sugarcrm database. we have modified the database for backend integration with our telephony system as well as our predictive dialer system so we have numerous stored procedures as well as additional columns and additional tables that feed our business solution. We created the stored procedure right in the same database and the call to it works perfectly! Thanks for the help and the prompt answer. I am a php newbie, I am straining to understand php as i am so used to visual basic and it is a totally different animal. I just cant seem to grasp the php, but with some sample code I can usually run with it and get it to work!
    As soon as i added the global for the db it ran without a hitch!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 10
    Last Post: 2010-11-16, 02:41 AM
  2. Replies: 0
    Last Post: 2010-08-18, 03:01 PM
  3. How to execute a logic hook in EditView??
    By EDUCASTREAM in forum Help
    Replies: 7
    Last Post: 2010-03-14, 03:28 AM
  4. Replies: 3
    Last Post: 2009-08-15, 03:00 AM
  5. Create listview with stored procedure
    By ivit in forum Developer Help
    Replies: 2
    Last Post: 2008-07-31, 11:26 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •