Results 1 to 5 of 5

Thread: Problems accessing EmailAddresses as a related module

  1. #1
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Problems accessing EmailAddresses as a related module

    Hello,

    I'm trying to set up a double opt in/opt out solution for my company's newsletter. For the opt out process, I have a script that the unsubscribee (Lead) can run from their email that changes a custom checkbox field. I have a Workflow definition that, when it notices this field has changed, runs its alerts/actions. I would like it to change the field opt_out in the Lead's related email to be true, and I set up the workflow definition as such, but it just doesn't. It appears that the email address relationship doesn't get recognized, as I can change fields in other related modules, just not Email Addresses. At the very least I know the Lead has the correct email address, as in the same workflow definition I can send an alert email to the recipient (and even place the email address as a variable in the template) but as far as the actual relationship is concerned, I can't tell if its there (I'm using Sugar On Demand so I don't have direct database access to the email_addr_bean_rel table to see if its there). Anyone able to recreate this situation or tell me what I'm doing wrong?

    Further information:

    I'm working in SugarCRM Pro 6.

    Workflow looks like this:

    Execution Occurs: When record saved Status: Active
    Target Module: Leads Applies to: Existing Records Only
    Processing Order: Actions then Alerts

    Conditions

    Description: Value:
    When double opt changes to or from specified value Equals Yes
    These operations will be performed:

    Alerts

    Details Type: Event Description:

    Actions

    Details Type: Event Description:
    Show Actions Update field(s) in a related EmailAddress
    Show Actions Update fields in the target module

    I'll have it be known that the second action does fire, just not the first.

    What's more, this problem also seems to be in the SOAP interface. Here's the code I use to fire the above workflow:

    PHP Code:
    //Find this Lead based off the email address
    $search_by_module_params = array(
        
    'user_name' => $username,
        
    'password' => $password,
        
    'search_string' => $_REQUEST['email'],
        
    'modules' => array('Leads'),
        
    'offset' => 0,
        
    'max_results' => 1
        
    );
                    
    $search_by_module_result $client->call('search_by_module'$search_by_module_params);
                
    $entry_id $search_by_module_result['entry_list'][0]['id'];
        
    //Set the double opt out parameter to true. SugarCRM should recognize this and run an
    //internal script to opt out the email associated with this lead.
    $set_entry_params = array(
        
    'session' => $session_id,
        
    'module_name' => 'Leads',
        
    'name_value_list' => array(
            array(
    'name' =>'id'
                
    'value' => $entry_id),
            array(
    'name' => 'double_opt_c'
                
    'value' => 'true')
            )
        );

    $set_entry_result $client->call('set_entry'$set_entry_params); 
    Note that the set entry call works here. If I try to solve the email address problem using SOAP, I can retrieve the email address, but I can't seem to modify it. Code below:

    PHP Code:
    //Get all the entries with the same email address as the email address provided
    $get_entry_list_params = array(
        
    'session' => $session_id,
        
    'module_name' => 'EmailAddresses',
        
    'query' => 'email_address=\''.$_REQUEST['email'].'\'',
        
    'order_by' => '',
        
    'offset' => 0,
        
    'select_fields' => array('id''email_address''opt_out'),
        
    'max_results' => 10,
        
    'deleted' => 'false');
                
    $get_entry_list_results $client->call('get_entry_list'$get_entry_list_params);
        
    $entry_id $get_entry_list_results['entry_list'][0]['name_value_list'][0]['value'];

    //Lets double check this is the right email
    $get_entry_params = array(
        
    'session' => $session_id,
        
    'module_name' => 'EmailAddresses',
        
    'id' => $entry_id,
        
    'select_fields' => array('email_address'));
        
    $get_entry_results $client->call('get_entry'$get_entry_params);

    foreach(
    $get_entry_results['entry_list'][0]['name_value_list'][0] as $key2 => $value2)
    {
        echo 
    '--'.$key2.' => '.$value2.'<br/>';
    }

    echo 
    "<br/>";

    $set_entry_params = array(
        
    'session' => $session_id,
        
    'module_name' => 'EmailAddresses',
        
    'name_value_list' => array(
            array(
    'name' =>'id'
                
    'value' => $entry_id),
            array(
    'name' => 'opt_out'
                
    'value' => 'true')
            )
        );

    $set_entry_result $client->call('set_entry'$set_entry_params);

    foreach(
    $set_entry_result['error'] as $key => $value)
    {
        echo 
    $key.' => '.$value.'<br/>';

    The script returns the following:
    HTML Code:
    --name => email_address<br/>
    --value => test@test.com<br/>
    <br/>
    number => 0<br/>
    name => No Error<br/>
    description => No Error<br/>
    This means its correctly finding the email address and I can access the email address by id, and its saying it has no error in the set_entry command. However, when I go into the Lead record, the opt out field is still false.

  2. #2
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: Problems accessing EmailAddresses as a related module

    So I'm still working on this problem, here's a bit more information about it. As far as the SOAP API is concerned, there's some funny business. Through SOAP, I can adjust a records deleted status, but not its opt out status. These are the same type of variable in the same record, so its rather odd that I can modify one but not the other. Code to do so below:
    PHP Code:
    //Look at our email addresses
    $gel_params = array(
        
    'session' => $session_id,
        
    'module_name' => 'EmailAddresses',
        
    'query' => '',
        
    'order_by' => '',
        
    'offset' => '0',
        
    'select_fields' => array('email_address''opt_out''deleted'),
        
    'deleted' => '0'
            
    );
        
    $gel_result $client->call('get_entry_list'$gel_params);

    var_dump($gel_result);

    //Change our emails
    $se_params = array(
        
    'session' => $session_id,
        
    'module_name' => 'EmailAddresses',
        
    'name_value_list' => array(
            array(
                
    'name' => 'id',
                
    'value' => $gel_result['entry_list'][0]['id']
                ),
            array(
                
    'name' => 'deleted',
                
    'value' => '1'
                
    ),
            array(
                
    'name' => 'opt_out',
                
    'value' => '1'
                
    )
            )
        );
        
    $se_result $client->call('set_entry'$se_params);

    //var_dump($se_result);

    //See what changed
    $gel_params = array(
        
    'session' => $session_id,
        
    'module_name' => 'EmailAddresses',
        
    'query' => '',
        
    'order_by' => '',
        
    'offset' => '0',
        
    'select_fields' => array('email_address''opt_out''deleted'),
        
    'deleted' => '1'
            
    );
        
    $gel_result $client->call('get_entry_list'$gel_params);

    var_dump($gel_result); 
    This script will find all your non deleted emails, delete one, and then display all your deleted emails, in which it will show your recently deleted email. It should also set the opt out flag, but it doesn't.

    Anyone know if its possible somehow to use cURL to reroute a request through removeme.php?

  3. #3
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: Problems accessing EmailAddresses as a related module

    So I tried to delve deeper using logic hooks, and I'm still having problems. Logic hook code below

    logic_hooks.php
    PHP Code:
    <?php

    /*
    *    Logic hook for webpage widget
    *    This file MUST be named logic_hooks.php
    */

    $hook_version 1;

    $hook_array = Array();

    //The parameters in a logic hook are execution order, identifier, location of class file, class, function
    $hook_array['before_save'][] = Array(1'webpageWidget',
        
    'custom/modules/Leads/WebpageWidget.php''WebpageWidget',
        
    'modifyLead');

    ?>
    WebpageWidget.php:
    PHP Code:
    <?php

    class WebpageWidget
    {    
        
        function 
    modifyLead(&$bean$event$arguments)
        {
            if (!
    defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 
            
            
    //If this Lead is flagged to opt out, then opt out the email address
            
    if($bean->set_opt_c == || $bean->fetched_row['set_opt_c'] == 1)
            {
                
    $query 'UPDATE email_addresses e, email_addr_bean_rel r SET e.opt_out = true WHERE e.id = r.email_address_id AND r.primary_address = true AND r.bean_id = "'.$bean->id.'"';
            
                
    $bean->db->query($query);
            
                
    $bean->set_opt_c 0;
            }
        }

    }
    ?>
    As you can see, I'm directly accessing the database. The query goes through fine, no errors, but the flag doesn't set. I'm really at a loss.
    Last edited by robertbmirth; 2010-08-02 at 09:26 PM.

  4. #4
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: Problems accessing EmailAddresses as a related module

    So... looking at my log for this stuff, I see the following:

    08/02/10 14:22:42 [2068][1][INFO] Query:UPDATE email_addresses e, email_addr_bean_rel r SET e.opt_out = true WHERE e.id = r.email_address_id AND r.primary_address = true AND r.bean_id = "74b66d1b-ff2b-47d7-8d27-4c534089ccc9"

    and then a few lines later:

    08/02/10 14:22:42 [2068][1][INFO] Query:update email_addresses set invalid_email=0, opt_out=0,date_modified = '2010-08-02 21:22:42' where id='afa95a52-2a2e-e707-aae4-4c52012672dc'

    The bean_id does correctly relate to the email id, so don't get confused that they're different.

    I've delved around through SugarCRM's source to find the root of this problem, and it seems to be in the SugarEmailAddress class, namely the function AddUpdateEmailAddress($addr,$invalid=0,$opt_out=0) . Inside the function there's the same exact form for the query that sets the opt_out back to 0. My problem is that even though I'm fairly certain that this method is being called, I can't find out what's calling it. And what's worse is that every time it seems to be called directly after whatever SQL statement I use to try to set the opt_out flag, so it seems like my code is calling it, but there's nothing in my code to do such a thing. Furthermore, it doesn't matter if I set the hook to execute before or after a save, the same statement seems to get called right after. This problem has had me stuck for days, and any assistance would be extremely helpful.

  5. #5
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: Problems accessing EmailAddresses as a related module

    Solution:

    PHP Code:
    class WebpageWidget  
    {      
          
        function 
    modifyLead(&$bean$event$arguments)  
        {  
            if (!
    defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');   

            if(empty(
    $bean->set_opt_c)) 
                
    $bean->set_opt_c 0

            
    $bean->emailAddress->addresses[0]['opt_out'] = $bean->set_opt_c

        }  



Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Problems accessing system
    By JAldrich in forum Help
    Replies: 3
    Last Post: 2010-05-20, 08:02 PM
  2. Replies: 1
    Last Post: 2010-03-19, 06:39 PM
  3. Replies: 8
    Last Post: 2010-01-08, 09:16 AM
  4. Replies: 0
    Last Post: 2009-03-30, 07:05 AM
  5. Module Detail View show List of Related->Related
    By theLowlyContractor2 in forum Help
    Replies: 0
    Last Post: 2008-09-11, 03:32 PM

Tags for this Thread

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
  •