Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: HELP! Launching web service through logic_hook

  1. #1
    fedepia is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    Rosario, Argentina
    Posts
    104

    Default HELP! Launching web service through logic_hook

    Hello people! how are you? i need to execute a set_entry web service call before to create an account.
    I looked for something that can raise this and I could find this link but i didn't understand how i can raise that i need.
    I created a logic_hook.php file under the \module\Accounts dir with the following body:
    PHP Code:
    <?php
        $hook_array
    ['before_save'][] =
            Array(
    1
                  
    'Call_hook'
                  
    'modules/Accounts/updateDescription.php'
                  
    'updateDescription'
                  
    'before_save');
    ?>
    then I created my class like:
    PHP Code:
    <?php
    class updateDescription {
        function 
    updateDescription(&$bean$event$arguments) {
            
    $bean->description html_entity_decode($bean->description);
            
    $bean->fetched_row['description'] = $bean->description;
        }
    }
    ?>
    Could anybody help me with the code that i have to write to raise the set_entry??

    Thanks in advance!!

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

    Default Re: HELP! Launching web service through logic_hook

    fedepia,

    Create the logic_hook.php file under custom/modules/Accounts and make sure your updateDescription.php file is in modules/Accounts (not custom/modules/Accounts unless you specify that path). There looks like you need a couple of small changes in the logic_hook file:
    PHP Code:

        $hook_array
    ['before_save'][] =
            Array(
    1
                  
    'updateDescription'
                  
    'modules/Accounts/updateDescription.php'
                  
    'updateDescription'
                  
    'updateDescription'); 
    I thought that I recall there being some sort of issue with the class name being the same as the function. If there is and you still have issues try changing your class:

    updateDescription.php changed to Accounts_cstm.php (to avoid confusion)
    PHP Code:

    class Accounts_cstm {
        function 
    updateDescription(&$bean$event$arguments) {
            
    $bean->description html_entity_decode($bean->description);
            
    $bean->fetched_row['description'] = $bean->description;
        }

    and then your logic hook:

    PHP Code:

        $hook_array
    ['before_save'][] =
            Array(
    1
                  
    'updateDescription'
                  
    'modules/Accounts/Accounts_cstm.php'
                  
    'Accounts_cstm'
                  
    'updateDescription'); 

  3. #3
    fedepia is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    Rosario, Argentina
    Posts
    104

    Default Re: HELP! Launching web service through logic_hook

    thank you for answer. I fixed the code but it still doesn't work. That I'm trying to do is, when i add an account then a set_entry web services is launched.
    Here is the code for logic_hook.php
    PHP Code:
    <?php
        $hook_array
    ['before_save'][] =
            Array(
    1,
            
    'Call_hook',
            
    'modules/Accounts/updateDescription.php',
            
    'AccountHookHandler',
            
    'createLead');
    ?>
    and the following is the code that i want to execute
    PHP Code:
    <?php
    class AccountHookHandler {
        function 
    createLead(&$bean$event$arguments) {
            
    //$bean->description = html_entity_decode($bean->description);
            //$bean->fetched_row['description'] = $bean->description;

            
    $client = new nusoapclient("http://localhost/sugarcrm/soap.php?wsdl"true);

            
    $user_auth = array(
                
    'user_auth' => array(
                
    'user_name' => 'admin',
                
    'password' => md5('admin')
            ));

            
    $login_results $client->call('login',$user_auth);
            
    $session_id $login_results['id'];

            
    $user_guid $soapclient->call('get_user_id',$session_id);

            
    $set_entry_params = array(
               
    'session' => $session_id,
               
    'module_name' => 'Leads',
               
    'name_value_list'=>array(
                   array(
    'name'=>'first_name''value'=>'FEDE PHP'),
                   array(
    'name'=>'last_name''value'=>'PIA PHP'),
                   array(
    'name'=>'status',     'value'=>'New'),
                   array(
    'name'=>'phone_work''value'=>'0880038383'),
                   array(
    'name'=>'phone_fax''value'=>''),
                   array(
    'name'=>'account_name''value'=>''),
                   array(
    'name'=>'lead_source''value'=>'Web Site'),
                   array(
    'name'=>'description''value'=>'PROBANDO INSERCION DESDE PHP'),
                   array(
    'name'=>'assigned_user_id''value'=>$user_guid)));

             
    $result $soapclient->call('set_entry',$set_entry_params);
        }
    }
    ?>
    thanks again

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

    Default Re: HELP! Launching web service through logic_hook

    Just to make sure it's not some naming conflict with the way Sugar handles logic hooks can you renamed the updateDescription.php file to AccountHookHandler.php and then change the logic_hook to
    PHP Code:
    <?php
        $hook_array
    ['before_save'][] =
            Array(
    1,
            
    'createLead',
            
    'modules/Accounts/AccountHookHandler.php',
            
    'AccountHookHandler',
            
    'createLead');
    ?>
    And to verify that it's getting to your hook add a debug statement to the top of createLead:
    PHP Code:
    class AccountHookHandler {
        function 
    createLead(&$bean$event$arguments) {
            
    //$bean->description = html_entity_decode($bean->description);
            //$bean->fetched_row['description'] = $bean->description;

    $GLOBALS['log']->fatal("Executing AccountHookHandler..."); //check sugarcrm.log to see if this is getting called

            
    $client = new nusoapclient("http://localhost/sugarcrm/soap.php?wsdl"true);
    ............. 
    Good luck!

  5. #5
    fedepia is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    Rosario, Argentina
    Posts
    104

    Default Re: HELP! Launching web service through logic_hook

    thank you for answer again. I fixed the code but it still doesn't work.
    The code for logic_hook.php is
    PHP Code:
    <?php
        $hook_array
    ['before_save'][] =
            Array(
    1,
            
    'Call_hook',
            
    'modules/Accounts/updateDescription.php',
            
    'AccountHookHandler',
            
    'createLead');
    ?>
    and the code for AccountHookHandler is
    PHP Code:
    <?php
    class AccountHookHandler {
        function 
    createLead(&$bean$event$arguments) {
            
    //$bean->description = html_entity_decode($bean->description);
            //$bean->fetched_row['description'] = $bean->description;

            
    $GLOBALS['log']->fatal("Executing AccountHookHandler..."); //check sugarcrm.log to see if this is getting called

            
    $client = new nusoapclient("http://localhost/sugarcrm/soap.php?wsdl"true);

            
    $user_auth = array(
                
    'user_auth' => array(
                
    'user_name' => 'admin',
                
    'password' => md5('admin')
            ));

            
    $login_results $client->call('login',$user_auth);
            
    $session_id $login_results['id'];

            
    $user_guid $soapclient->call('get_user_id',$session_id);

            
    $set_entry_params = array(
               
    'session' => $session_id,
               
    'module_name' => 'Leads',
               
    'name_value_list'=>array(
                   array(
    'name'=>'first_name''value'=>'FEDEPHP'),
                   array(
    'name'=>'last_name''value'=>'PIAZPHP'),
                   array(
    'name'=>'status''value'=>'New'),
                   array(
    'name'=>'phone_work''value'=>'0880038383'),
                   array(
    'name'=>'phone_fax''value'=>''),
                   array(
    'name'=>'account_name'value'=>''),
                   array('
    name'=>'lead_source', 'value'=>'Web Site'),
                   array('
    name'=>'description', 'value'=>'PROBANDO INSERCION DESDE PHP'),
                   array('
    name'=>'assigned_user_id','value'=>$user_guid)));

             $result = $soapclient->call('
    set_entry,$set_entry_params);
        }
    }
    ?>
    the sugarcrm.log doesn't report anything, i think my class is never called but i don't now what i can do. What do you think??
    thanks again
    Last edited by fedepia; 2007-09-13 at 10:06 AM.

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

    Default Re: HELP! Launching web service through logic_hook

    Perhaps I was too confusing. Try changing the logic hook to the example I put above and change the name of the file itself from updateDescription.php to AccountHookHandler.php

    logic_hook.php:
    PHP Code:
    <?php
        $hook_array
    ['before_save'][] =
            Array(
    1,
            
    'createLead',
            
    'modules/Accounts/AccountHookHandler.php',
            
    'AccountHookHandler',
            
    'createLead');
    ?>

    This is KEY.

  7. #7
    fedepia is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    Rosario, Argentina
    Posts
    104

    Default Re: HELP! Launching web service through logic_hook

    egg... i'm sorry you weren't too confusing at all, i put my old code . I did the changes like you said but nothing has happened.
    I show you the code for logic_hooks.php
    PHP Code:
    <?php
        $hook_array
    ['before_save'][] =
            Array(
    1,
                  
    'createLead',
                  
    'modules/Accounts/AccountHookHandler.php',
                  
    'AccountHookHandler',
                  
    'createLead');
    ?>
    a the follow is the code for AccountHookHandler.php
    PHP Code:
    <?php
    class AccountHookHandler {
        function 
    createLead(&$bean$event$arguments) {
            
    //$bean->description = html_entity_decode($bean->description);
            //$bean->fetched_row['description'] = $bean->description;
            
            //check sugarcrm.log to see if this is getting called
            
    $GLOBALS['log']->fatal("Executing AccountHookHandler..."); 

            
    $client = new nusoapclient("http://localhost/sugarcrm/soap.php?wsdl"true);

            
    $user_auth = array(
                
    'user_auth' => array(
                
    'user_name' => 'admin',
                
    'password' => md5('admin')
            ));

            
    $login_results $client->call('login',$user_auth);
            
    $session_id $login_results['id'];

            
    $user_guid $soapclient->call('get_user_id',$session_id);

            
    $set_entry_params = array(
               
    'session' => $session_id,
               
    'module_name' => 'Leads',
               
    'name_value_list'=>array(
                   array(
    'name'=>'first_name''value'=>'FEDEPHP'),
                   array(
    'name'=>'last_name''value'=>'PIAPHP'),
                   array(
    'name'=>'status''value'=>'New'),
                   array(
    'name'=>'phone_work''value'=>'0880038383'),
                   array(
    'name'=>'phone_fax''value'=>''),
                   array(
    'name'=>'account_name''value'=>''),
                   array(
    'name'=>'lead_source','value'=>'Web Site'),
                   array(
    'name'=>'description''value'=>'PROBANDO INSERCION DESDE PHP'),
                   array(
    'name'=>'assigned_user_id','value'=>$user_guid)));

             
    $result $soapclient->call('set_entry',$set_entry_params);
        }
    }
    ?>
    it still doesn't work and the log doesn't report anything. Any idea?

    Bye thanks!!
    Last edited by fedepia; 2007-09-13 at 10:58 AM.

  8. #8
    fedepia is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    Rosario, Argentina
    Posts
    104

    Default Re: HELP! Launching web service through logic_hook

    egg!! i'm a really stupid man, the logger reports and all the problems were because (i insist) i am an asshole offcourse... and put the logic_hooks.php file in the same directory of AccountHookHandler.php i.e. in modules/Account directory and not in custom/modules/Accounts.

    I really apreciate all the help that you brought to me.

    Thank you so very much.

    Greetings!

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

    Default Re: HELP! Launching web service through logic_hook

    Glad to hear you got it working! Just an FYI; that logic_hook.php file gets dynamically built by Sugar. You may want to package your update and use the module installer to load it into Sugar so that the logic_hook.php file doesn't get wiped out in the future. Just create a pre_install.php file in the scripts directory of the install zip with these contents (see wiki for more info on building a custom module package):
    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    function 
    pre_install() {
        require_once(
    'include/utils.php');
        require_once(
    'ModuleInstall/ModuleInstaller.php');

    check_logic_hook_file("Accounts","before_save",array(1,'createLead','modules/Accounts/AccountHookHandler.php','AccountHookHandler','createLead'));


    }

    ?>

  10. #10
    fedepia is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    Rosario, Argentina
    Posts
    104

    Default Re: HELP! Launching web service through logic_hook

    thank you egg i'll keep in mind.

    I'd like to ask you, now that it's worked, how can i do to cancel the insert of an account when the before_save hook raises up.

    That i want to do is, when a sugar's user creates an Account, check before to save it if a set_entry execution was success. if it was ok then the account would be created, by other hand if all went wrong so i want to cancel the account insert

    If my english was horrible, please tell me and i will repeat

    Thank you again

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Is the SugarCRM Web Service really that slow?
    By timothyp in forum General Discussion
    Replies: 15
    Last Post: 2010-12-15, 04:37 PM
  2. Benefits of SOAP Web Service over ADO?
    By WizRider in forum Developer Help
    Replies: 3
    Last Post: 2007-06-21, 03:17 PM
  3. Web Service call to Create Case always returns 0
    By markellul in forum Developer Help
    Replies: 4
    Last Post: 2007-06-19, 09:49 PM
  4. Web Service for the user roles
    By derekvincent in forum Developer Help
    Replies: 3
    Last Post: 2007-06-15, 01:25 AM
  5. Backup as web service or cron-executable routine
    By eeric in forum Feature Requests
    Replies: 1
    Last Post: 2005-10-05, 06:28 PM

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
  •