Profile picture for user admin
Daniel Sipos
18 Jan 2013

I’ve been learning CiviCRM in Drupal lately and there was an issue I ran into that bugged me for days: how to search for some contacts that meet certain criteria AND the ones that relate to them via a certain relationship? And I finally figured it out...

For example, I had two types of contacts: organisations and individuals employed in the organisations. So your classic employer-employee relationship. But how to search for the organisations in a certain country and bring them up together with the employees working for those organisations? Easy right? Well, perhaps, but boy I banged my head against the wall...

You’d think that given the complexity of the Advanced Search, it’s logical to have like a checkbox to select for the result page to also include contacts of relationship X. But no. Anyway, after many tries and no luck finding a solution online, evrika!

When you do the Advanced Search, you have to select under Display Results As - Related Contacts and specify which relationship you want the results to show. So, if select there employee and search for all the organisations in the US, you will get as a result all the people working in all the organisations in the US - but not the organisations themselves.

To get both, you need to save this result as a smart group, and perform the search again, but without the last step. By this I mean to skip changing the Display Results As setting. Save this group too and then merge the two in whatever context you need them - either into a third inclusive group, or in your mailing or whatever.

Hope this helps.

Profile picture for user admin

Daniel Sipos

CEO @ Web Omelette

Danny founded WEBOMELETTE in 2012 as a passion project, mostly writing about Drupal problems he faced day to day, as well as about new technologies and things that he thought other developers would find useful. Now he now manages a team of developers and designers, delivering quality products that make businesses successful.

Contact us

Comments

Florian Motteau 13 Mar 2015 11:11

The same with several relationship types ?

Hi,
This post helped me a lot, but now I would like to do the same but using multiples relationship types. For example if you have a relationship "CIO of" between individuals and companies, I would like to be able to fetch all indivuals that are employees or CIO of all companies. Do you have an idea to do so ? I think I could create smart groups for each relationship types and merge them but maybe there is an easier solution ?

Add new comment