3

I have been trying to work out how to create a Drupal View to allow end users to select an Organisation and then it displays Contacts given a specific relationship type. eg Select Employer Name (Organisation) - display Employees of Employer Relationship is the built-in Employer of / Employee Of

So far I have created a view with CiviCRM:Contact type and added a few fields, but the only 'relationship' details i can retrieve that is close for the 'employees' side of things is "CiviCRM Relationships: Contact ID B (Contact ID B)". I dont see to have or can find a method to display Contact B's Display Name

Example - Selected organisation is Contact 'A' ID 203 'K&N Brass' and has a relationship to Contact 'B' who's ID=202

Contact ID  Display Name    Relationship Type A-to-B    Contact ID B
203         K&N Brass       Band includes member        202

Drupal 7.43 CiviCrm 4.7.7 Views: 7.x-3.13

3 Answers 3

6

To create a Drupal relationship in a View for contacts A - B or B - A you need to add 2x Drupal relationship.

In the case of starting with the Org assuming it as at the B end of the relationship, first you choose the option that says

  • CiviCRM Contacts: CiviCRM Relationship (starting from Contact B)

and configure that with the relevant Relationship Type

Then you choose

  • CiviCRM Relationships: Contact ID A

and use the relationship you created above to Join contact A via the relationship to contact B.

Then as Laryn says, select a field for DisplayName and tell it to use the second of these relationships (probably only one that shows in that context) and bingo!

7
  • Thanks. after some fiddling and reversing the logic above, I now have it displaying Organisation Name and Contact name. But I cant seem to add a filter to allow the user to then filter the results to only a particular Organisation. Looking at the filters the CiviCRM Contacts: Organisation field is not in the list. Also, how can I make that filter then display all the organisations rather than the user having to type in a name?
    – DMOZ
    Commented May 12, 2016 at 6:05
  • Filter should allow you to add Display Name, and again select the Relationship to tell the filter to be applying to the Contact B v A (or vv)
    – petednz - fuzion
    Commented May 12, 2016 at 7:32
  • yes, I can select Display Name in the filters option. 2x Issues:: 1. I want to filter on the Contacts - Organisation Name, but even with a basic view which simply displays contacts as a list in the view the Organisation Name field doesnt seem to be exposed to views. So this feels like a bug?? 2. Having created a filter, is there a way to have the filter values displayed via a drop-down style option. eg Can you have a drop-down filter selector which is pre-populated from all (unique) CiviCRM Address: State/Province values? I can only see that you can have a typed in field value
    – DMOZ
    Commented May 13, 2016 at 2:06
  • want to skype me? it may be much easier to point at something to clarify at this point peter.davis59 also much better if you break those out as new questions if the skype doesn't sort it
    – petednz - fuzion
    Commented May 13, 2016 at 4:52
  • I've sent you a skype contact request
    – DMOZ
    Commented May 13, 2016 at 23:18
1

Once you have the relationship in place, you should be able to add a new field to the view (e.g. "Display Name") and in the settings for this field, tell it to use that relationship that you've set up.

1

to all that may come across this

After putting my CiviCRM project on hold for a few months I came back to it having found no other better solutions to my needs and came across this

Drupal Views - Sorting of family members in a contact list

which has images and step-by-step guide and got my view returning what I need for the moment..... next is getting it to display the View on the main site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.