Linking Contact to multiple accounts

v 7.2.2. How to link a Contact to more than one account? Have seen Sugar method but I don’t see anything in Suite Studio that can be activated to provide the ‘Link’ action item.

you can always create a many to many relationship in studio

best regards

Mike - thanks. I did so and can now show my contact belonging to two accounts in addition to the primary Account Name. Do you know how I can get these two additional accounts to show in a Report or View Export for the contact? Would I need to create a new Contact/Report relationship?

Just a small note: currently accounts-contacts are a many-to-many relationship “under the hood”, although the user interface only exposes them as a one-to-many (one account - many contacts).

I was using PHP code to connect accounts to contacts and I noticed that it will let you add a second account to a contact. Only one of them will be shown in detail views, but if you list the contacts in any of the two accounts they will be there.

Then I read online about this, it’s a known behavior.

I didn’t try ways of doing it with the user interface, but they might be there. Maybe you can link the second account from a subpanel or something.

But if you’re going to create custom code to show two accounts, you might as well use the default accounts module and relationship. You will probably have less things to change…

1 Like

Here a good link for you:

http://support.sugarcrm.com/Knowledge_Base/End_Users/Accounts/Understanding_the_Accounts-Contacts_Relationship/

EDIT: I just re-read your first post and I now think you already knew all of this in SugarCRM… sorry, my fault not understanding exactly where you were with this issue.

1 Like

Ok, so this issue also interests me so I went and did some tests, while checking what was getting created in the database (table accounts_contacts.

I found it’s very possible (and easy) to add a second account to a contact. All you need to do (after adding him to the first account) is go into the second account detail view, scroll down to the contacts subpanel, click select, and then Search for your contact and select him.

SuiteCRM will NOT replace the Contact’s existing account connection, it will add a second one. This can be confirmed via myPhpAdmin.

What I would like to know is how to display this in the Contact’s detail view. I would love to show there something like this:
Account name: someaccount, someotheraccount

1 Like

And here’s a brilliant (not mine) piece of SQL to list all the accounts of a given Contact:

SELECT 
         #contacts.first_name, contacts.last_name,
         GROUP_CONCAT(accounts.name SEPARATOR ', ')
    FROM accounts_contacts
    JOIN accounts ON accounts_contacts.account_id = accounts.id
    JOIN contacts ON accounts_contacts.contact_id = contacts.id
    WHERE contacts.id='be7e96c0-b783-f21d-0ff2-56a009373ec3'
	GROUP BY contacts.id
	ORDER BY accounts_contacts.date_modified DESC

This is MySQL specific, won’t work on other databases, I’m afraid.

Replace that id with the actual Contact id you’re looking for. Tweak the ORDER BY to match your preferences.

Now I just need to figure out how to put that inside a detail view. And a subpanel.

@127bit, tell me if this is helping or if I am hijacking your thread… I don’t mean to.

1 Like

PGR: Selecting the contact from a second Account replaces the contact’s original Account name with the new one, as it did before I created the custom Account/Contact man/many relationship.

When you say it replaces, did you check in the database or do you just mean that the new name is showing instead of the old one? That’s because the UI (user interface) assumes only one account per contact, so it just uses any one, the most recent.

There are several ways to verify this without going into the database:

  1. remove the second account and watch SuiteCRM show you the first account again
  2. go into the first account, see its list of contacts and verify that the contact is still there

pgr: The results from the sequence of events you described was correct, thanks for the confirmation. Sounds like the the UI can’t provide the multiple accounts export, which sucks big time. I’m surprised that the custom relationship isn’t (so far) creating a pointer from the contact to subsequent accounts. Wonder if something can be done in phpMyAdmin ( Ihaven’t tried anything yet)?

I just came across this old thread, but I see the link up there is getting a lot of clicks, so I think it’s useful to also link here a post I made a while ago:

This is my “accumulated wisdom” on this subject. :slight_smile:

@pgr is correct, when it comes to SuiteCRM Version 8.1.3. You can link one contact to several accounts.
Downside is, as he/she mentioned, that in listview/detailview will only show one of the accounts.
However, if you go to each of the accounts, you will see the contact simultaneously under both or more.