Results 1 to 8 of 8

Thread: Contact Last email

  1. #1
    twick100 is offline Sugar Community Member
    Join Date
    Jun 2011
    Posts
    30

    Default Contact Last email

    We do email campaigns, is it possible to display a field in contacts with the last email and be able to use it in search filters?

  2. #2
    rafael.q.g@hotmail.com's Avatar
    rafael.q.g@hotmail.com is offline Sugar Community Member
    Join Date
    Jun 2011
    Location
    Florianópolis - Brazil
    Posts
    782

    Default Re: Contact Last email

    Yes it is. Once the search filters works based on database values, my option is that the esiest way to do that is:
    1. creating a new field on contacts to store this information.
    2. Program an scheduled task to get this info from mails and write in this new field.
    3. Add the new concacts field in contacts search panel.
    Rafael Queiroz Gonçalves
    Advanced OMG UML Certified Professional
    Sun Certified Enterprise Architect for the Java Platform
    Sun Certified Programmer for the Java 2 Platform
    IBM Certified Advanced Application Developer - Lotus Notes and Domino
    IBM Certified Application Developer - IBM WebSphere Portlet Factory
    Computer Science Mastering / UFSC - PPGCC

  3. #3
    christianknoll's Avatar
    christianknoll is offline Sugar Community Member
    Join Date
    Nov 2008
    Location
    Vienna
    Posts
    939

    Default Re: Contact Last email

    Hmmm .. why not do it as follows:

    (1) overwrite view.detail.php for the module you want his in read the info dynamically into a nonDB field on the module that you can display in the view
    (2) to search by look e.g. at modules/Contacts/metadata/SearchFields.php and see how the email address is used to search by. Define the same subquery with a may statement on the last email.

    With that no need to store redundant information and also no need to monitor a scheduled job running ... ;-)

    christian.

    Quote Originally Posted by rafael.q.g@hotmail.com View Post
    Yes it is. Once the search filters works based on database values, my option is that the esiest way to do that is:
    1. creating a new field on contacts to store this information.
    2. Program an scheduled task to get this info from mails and write in this new field.
    3. Add the new concacts field in contacts search panel.

  4. #4
    twick100 is offline Sugar Community Member
    Join Date
    Jun 2011
    Posts
    30

    Default Re: Contact Last email

    Thanks, going to try the suggested methods. Will be back.

  5. #5
    twick100 is offline Sugar Community Member
    Join Date
    Jun 2011
    Posts
    30

    Default Re: Contact Last email

    Quote Originally Posted by christianknoll View Post
    Hmmm .. why not do it as follows:

    (1) overwrite view.detail.php for the module you want his in read the info dynamically into a nonDB field on the module that you can display in the view
    (2) to search by look e.g. at modules/Contacts/metadata/SearchFields.php and see how the email address is used to search by. Define the same subquery with a may statement on the last email.

    With that no need to store redundant information and also no need to monitor a scheduled job running ... ;-)

    christian.
    Ok after much research I still don't understand this. I don't understand why I would be overwriting view.detail.php. There doesn't appear to be anything in that file I should modify.

    Can you give me an example?

  6. #6
    twick100 is offline Sugar Community Member
    Join Date
    Jun 2011
    Posts
    30

    Default Re: Contact Last email

    Ok... there has got to be an easier way to do this.

    I am going to reiterate for a moment.

    What I want is to search contacts based on when they were last emailed. I can easily display the last time they were emailed in a field via logic hook but that does not allow me to search based on the last email date.

    I am looking in SearchFields.php for Contacts module and I see this. Which is obviously getting the email address for the contact.

    PHP Code:
    'email' => 
      array (
        
    'query_type' => 'default',
        
    'operator' => 'subquery',
        
    'subquery' => 'SELECT eabr.bean_id FROM email_addr_bean_rel eabr JOIN email_addresses ea ON (ea.id = eabr.email_address_id) WHERE eabr.deleted=0 AND ea.email_address LIKE',
        
    'db_field' => 
        array (
          
    => 'id',
        ),
      ), 
    So I create this. Which should technically get the last email date that was sent to a particular contact.

    PHP Code:
    'last_email_c' => 
      array (
        
    'query_type' => 'default',
        
    'operator' => 'subquery',
        
    'subquery' => 'SELECT e.date_sent FROM emails e WHERE e.parent_type = \'Contacts\' AND e.parent_id = \'{0}\'',
        
    'db_field' => 
        array (
          
    => 'id',
        ),
      ), 
    However, I am not sure how to actually display the data in the list view. I checked through listviewdefs.php and I see no reference to either of these functions.

    What other steps am I missing?

  7. #7
    twick100 is offline Sugar Community Member
    Join Date
    Jun 2011
    Posts
    30

    Default Re: Contact Last email

    Update on this. I kind of have something but the logic is a bit off..

    in serchfields.php

    PHP Code:
    '_last_email' => 
      array (
        
    'query_type' => 'format',
        
    'operator' => 'subquery',
        
    'subquery' => 'SELECT e.parent_id id FROM emails e LEFT OUTWHERE DATEDIFF(NOW(),e.date_sent) > '.$_POST["_last_email_basic"].' OR e.date_sent is null',
        
    'db_field' => 
        array (
          
    => 'id',
        ),
      ), 
    in searchdefs.php

    PHP Code:
    '_last_email' => 
          array (
            
    'label' => 'Last Email Touched',
            
    'type' => 'int',
            
    'default' => true,
            
    'width' => '10%',
            
    'name' => '_last_email',
          ), 

    This does work, however, it only brings back records that are in the emails table. If there is a contact id that is not in that table than it doesn't show it.

    Due to the fact that it uses this as its subquery "
    PHP Code:
    ((contacts.id IN (SELECT e.parent_id id FROM emails e WHERE e.date_sent is null OR DATEDIFF(NOW(),e.date_sent) > 2))) 
    "

    Is it possible to supply NOT IN rather than IN?

  8. #8
    christianknoll's Avatar
    christianknoll is offline Sugar Community Member
    Join Date
    Nov 2008
    Location
    Vienna
    Posts
    939

    Default Re: Contact Last email

    You need to determine what the date is the last email was sent and populate this to the bean. You can also overwirt ethe class of the module that is inherited from SugarBean and overwrite the retrieve statement calling parent::retrieve and when this returns additonally select the max date of the retrieved email and populate this to the bean so the view can pick it up.

    View.detail.php is just onbe place where you can do this and the nice thing is that this can be done upgrade safe in the customs directory. The Modification of the core mOdule is not upgradesafe since you have to change Contact.php ..

    christian.

    Quote Originally Posted by twick100 View Post
    Ok after much research I still don't understand this. I don't understand why I would be overwriting view.detail.php. There doesn't appear to be anything in that file I should modify.

    Can you give me an example?

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Send Email to all email accounts of the contact
    By josedc15 in forum Developer Help
    Replies: 1
    Last Post: 2010-12-10, 02:25 PM
  2. email/contact versus email/account relationship?
    By jsbenson in forum General Discussion
    Replies: 2
    Last Post: 2010-01-27, 07:00 PM
  3. Replies: 1
    Last Post: 2009-11-27, 09:18 PM
  4. Replies: 1
    Last Post: 2009-08-11, 01:58 PM
  5. Replies: 0
    Last Post: 2007-06-21, 12:05 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
  •