Results 1 to 4 of 4

Thread: Export Contacts - Account ID

  1. #1
    heritagehc is offline Junior Member
    Join Date
    Sep 2010
    Posts
    2

    Default Export Contacts - Account ID

    When exporting contacts it does not bring out the associated account. Is there a way to pull an export of contacts and get the account id?

    Thanks!

  2. #2
    kuske's Avatar
    kuske is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Germany
    Posts
    2,597

    Default Re: Export Contacts - Account ID

    It's very simple.
    Each bean provides a function create_export_query which generates the query for all fields to be exported.
    In /modules/contacts/Contact.php you can add a line in function create_export_query to this query statement like that:

    PHP Code:
                             $query "SELECT
                                    contacts.*,email_addresses.email_address email1,
                                    accounts.name as account_name,
                                    accounts.id as account_id,
                                    users.user_name as assigned_user_name "

    Harald Kuske
    Pre-Sales Engineer Central Europe

    SUGARCRM Deutschland GmbH
    Erika-Mann-Str. 53, 80636 Munich, Germany
    Email: hkuske@sugarcrm.com
    Home: http://www.sugarcrm.com


  3. #3
    heritagehc is offline Junior Member
    Join Date
    Sep 2010
    Posts
    2

    Default Re: Export Contacts - Account ID

    I tried your suggestion and ended up with an extra column in my export file, but it was empty and had no entries. I know that the relationships exist between accounts and contacts, because I can see the appropriate contacts tied to each account inside sugar (and links to the account inside the contact views, etc.).

    Below is the function from my contact.php file (including your suggested edit):

    function create_export_query(&$order_by, &$where, $relate_link_join='')
    {
    $custom_join = $this->custom_fields->getJOIN(true, true,$where);
    if($custom_join)
    $custom_join['join'] .= $relate_link_join;
    $query = "SELECT
    contacts.*,email_addresses.email_address email1,
    accounts.name as account_name,
    accounts.id as account_id,
    users.user_name as assigned_user_name ";



    if($custom_join){
    $query .= $custom_join['select'];
    }
    $query .= " FROM contacts ";




    $query .= "LEFT JOIN users
    ON contacts.assigned_user_id=users.id ";



    $query .= "LEFT JOIN accounts_contacts
    ON ( contacts.id=accounts_contacts.contact_id and (accounts_contacts.deleted is null or accounts_contacts.deleted = 0))
    LEFT JOIN accounts
    ON accounts_contacts.account_id=accounts.id ";

    //join email address table too.
    $query .= ' LEFT JOIN email_addr_bean_rel on contacts.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module=\'Contacts\' and email_addr_bean_rel.deleted=0 and email_addr_bean_rel.primary_address=1 ';
    $query .= ' LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id ' ;

    if($custom_join){
    $query .= $custom_join['join'];
    }

    $where_auto = "( accounts.deleted IS NULL OR accounts.deleted=0 )
    AND contacts.deleted=0 ";

    if($where != "")
    $query .= "where ($where) AND ".$where_auto;
    else
    $query .= "where ".$where_auto;

    if(!empty($order_by))
    $query .= " ORDER BY ". $this->process_order_by($order_by, null);

    return $query;
    }

  4. #4
    maen is offline Sugar Community Member
    Join Date
    May 2008
    Posts
    45

    Default Re: Export Contacts - Account ID

    Hello, I have a similar task for export. I joined the contacts in export which is great. But I need a multiple join to get a colum from contacts_cstm. Unfortunately Im not able for this join.

    Example:

    In line 365 I modified the code like this:
    PHP Code:
                $custom_join $this->custom_fields->getJOIN(truetrue,$where);
                if(
    $custom_join)
                    
    $custom_join['join'] .= $relate_link_join;
                             
    $query "SELECT
                                    accounts.name as firma,
                                    accounts.billing_address_street as Rechnungsanschrift_Strasse,
                                    accounts.billing_address_postalcode as rechnungsanschrift_PLZ,
                                    accounts.billing_address_city as rechnungsanschrift_stadt,
                                    accounts.billing_address_country as rechnungsanschrift_land, 
                                    accounts.description as beschreibung,
                                
                                    contacts.salutation as Anrede,
                                    contacts.first_name as Vorname,
                                    contacts.last_name as Nachname,
                                    
                                    contacts.do_not_call as darf_angerufen_werden_ist_status_0,
                                    email_addresses.email_address FirmenEmail"

    And I put a join from line 395:
    PHP Code:
                            //join contacts from relation contacts and accounts_contacts
                            
    $query .= "LEFT JOIN accounts_contacts
                                        ON ( accounts.id=accounts_contacts.account_id and (accounts_contacts.deleted is null or accounts_contacts.deleted = 0))
                                        LEFT JOIN contacts
                                        ON accounts_contacts.contact_id=contacts.id "

    Works great! The issue: I need a contacts_cstm column for filter options in excel. Does anybody knows how to put this multiple join?

    Thnx in advance,

    Marc

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Export contacts
    By keymoo in forum General Discussion
    Replies: 7
    Last Post: 2012-05-11, 12:34 AM
  2. Replies: 5
    Last Post: 2010-03-01, 12:18 PM
  3. Replies: 0
    Last Post: 2007-10-21, 10:13 PM
  4. account-contacts export question
    By mol1 in forum General Discussion
    Replies: 1
    Last Post: 2007-09-01, 02:00 PM
  5. Replies: 0
    Last Post: 2006-08-28, 01:27 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
  •