4

I would like to create a view, or custom report, whoever is easier, to show the following: -The names of all contacts in a specific group -Some of their contact information -The names of all contacts in specific relationships with them (parent-child, for example) -Some of the contact information of the above.

When I created a view, I wasn't able to filter by group membership. And when I went to create a report I wasn't sure where to get started. Got any tips for me?

2
  • What prevented you using 'group' as a filter. Is it a Smart Group?
    – petednz - fuzion
    Sep 3, 2015 at 1:04
  • No, not a smart group. I simply see no option for groups under filter. I went around this by saying the relationship I describe below was required, but actually did not solve this part of my question yet.
    – naomisl
    Sep 3, 2015 at 1:56

3 Answers 3

2

Our need was for class rosters which included the one or two adults approved to pick up the child from class.

The result is a list which displays a child's info on the same line as the adult(s) approved for pick up.

For this solution we actually needed two views; View A shows the adults and is embedded into View B which lists the kids, using the contact ID from each of View B's kids to connect to the adults. The key to this working is the Drupal module Views Field View. This allows us to insert a View into another view as a Field.

===== View A "Picked Up By" (type: CiviCRM Contacts) =====

Format: Delimited text list (from the Drupal module Views Delimited List; this module is key because it allows us to insert the text OR into the result: "Adult A OR Adult B" and get both adults on the same line)

Under Advanced > Relationships

We use 2 relationships to list the adults:

  1. CiviCRM Contacts: CiviCRM Relationship (starting from Contact A)

    ~ Specific relationship type: Picked up by | Primary Pickup for (you could certainly use Parent | Child here)

    ~ Limit results only to active relationships

  2. CiviCRM Relationship : Contact ID B

    ~ Relationship: the relationship you just setup, CiviCRM Relationship (starting from Contact A)

    ~ Identifier: CiviCRM Contact B

Under Advanced > Contextual Filters

CiviCRM Contacts: Contact ID

  • Do not use a relationship (if it forces you to use a relationship, then delete the relationships, create this contextual filter first, then create the relationships)
  • When the filter value is NOT available, Hide view
  • Specify validation criteria

    -- Validator: Basic Validation

    -- Action to take... : Hide view

Fields

  • CiviCRM Contacts: First Name (using Relationship 2 - CiviCRM Contact B)

Filter Criteria

  • CiviCRM Contacts: Is Deleted - False (using Relationship 2 - CiviCRM Contact B)

Summary of how this works: The contextual filter takes the contact ID for the child (which will be supplied by the second view) and uses that as the contact ID for the first relationship. Then, the second relationship gets us to the adult as the Contact B of the Child/Adult relationship. Then you display the Name of the adult (and make sure that the adult hasn't been deleted with the filter criteria).

===== View B "Rosters" (type: CiviCRM Contacts) =====

Format: Table

No contextual filters or relationships needed

Fields

  • CiviCRM Contacts: Contact ID (this can be excluded from display, but needed later)
  • Child's Name (we use Sort Name)
  • Any other info you need for your kids
  • Here's the all important field supplied from the Views Field View module: View: Include View

For this field, you select which other view (View A) you would like to embed into this view (View B). So, for View to include, you select View A ("Picked_up_by" in our case). For number of arguments, 1. For Argument #1, you use: [id] which is the contact id from the field you excluded from display above.

Filter Criteria Filter the contacts in View B such that only the children you need listed are displayed, whether that is by tag (how we do it) or group or custom field.

This will also work with exposed filters as our rosters are divided up by a custom field "Grade" so we have an exposed filter on View B which allows us to select which Grade level we want to look at.

3
  • 1
    Wow, this is really complex, but also seems like a great workaround. I will give it a try and let you know how it goes!
    – naomisl
    Sep 4, 2015 at 1:58
  • 1
    ..and it works! Thank you so much! Some notes: If instead of "OR" you add the html "</td><td>" your inline fields will be separate cells in the table. If you do this, those fields must be placed on the end, because they will overwrite other cells. Also, if you are in Drupal 7 and Views Field View 7.x-1.1, instead of arguments there are contextual filters, and you use the token [!id].
    – naomisl
    Sep 9, 2015 at 0:40
  • Glad it worked for you! Happy to help. Sep 9, 2015 at 2:55
2

I will add this as an answer so i can add the screenshot. You 'should' be able to filter by Groups in a civicrm contact based View. In the screenshot you will see i have both Group Name and Group ID set as fields, and have Group ID set as an Exposed Filter. Hope that helps if only to confirm that something is amiss in the world of Views for you.

enter image description here(Note: on the first site i went to do this on I also did not have them available, but that is a Pantheon based site where things keep changing on me, on the second which is a standard-hosted site it all worked as expected. So you may not be alone with the Group fields being unavailable)

4
  • Thank you petednz! I'm going to see about exposing that option and report back.
    – naomisl
    Sep 3, 2015 at 17:50
  • This seems to work only if exposed, but that's workable. Thank you!
    – naomisl
    Sep 3, 2015 at 19:24
  • really? are you saying that if you 'apply' the filter and use the Group ID, but do not set it to be Exposed, then the filter does not work? If so that is a bug that needs fixing.
    – petednz - fuzion
    Sep 4, 2015 at 2:20
  • Yes, that was my experience. I will see if I can recreate the issue, and if so report it as a bug. I'm not completely confident I wasn't doing something else wrong somehow, so I'm going to check first.
    – naomisl
    Sep 8, 2015 at 19:22
1

I have managed to cobble together a view that mostly works:

go to admin/structure/views click "add new view" Show: civicrm contacts Display Format: Table fill out the rest of the fields as you like, then click "continue and edit"

In the view editor, click "advanced" under relationships, add the following:

CiviCRM Contacts: CiviCRM Relationship (starting from contact A) Choose the type of relationship you want. I chose Parent/child.

(CiviCRM Relationship (starting from contact A)) CiviCRM Relationships: Contact ID A Select "starting from contact A" Name this contact. I named it "child"

(CiviCRM Relationship (starting from contact A)) CiviCRM Relationships: Contact ID B Select "starting from contact A" Name this contact. I named it "parent."

Now that the relationships are in place, you can add your fields. for example, add a field "civicrm contacts: display name." it will give you the option to use a relationship. choose "child" from the drop down menu. Make sure to change the label to reflect what you've done. Then you can do the same thing again but this time pick "parent."

You will see a table that displays like so (please excuse my inability to create a table here):

Child Name | Parent Name


Tom Jones Jr | Tom Jones, Sr


Tom Jones Jr | Tabitha Jones

As you can see, the issue with this solution is that when a single child has two (or more) parents, that student is listed twice. If anyone has a solution to that issue, I'd be most grateful to have it. In an ideal world, the output would be as follows:

Child Name | Parent Name | Parent Name


Tom Jones Jr | Tom Jones, Sr | Tabitha Jones


I haven't yet reached that ideal state, but what I have does pull what I need, data-wise.

4
  • naomisl, we are in the same boat and did find a solution! I will post it tomorrow from work. It results in "Child Info | Parent Name or Parent Name". Sep 3, 2015 at 4:16
  • Allen, I would love to see that result! Thank you for sharing.
    – naomisl
    Sep 3, 2015 at 17:49
  • @AllenHutchison did you ever post your solution for this issue? We have a client that is looking for this functionality, we're in the process of deciding if a Drupal View would work or if we should create a custom report or search for them.
    – Evan
    Jul 17, 2018 at 23:43
  • @Evan, yes, please see the selected answer (green check mark) to the question. Jul 18, 2018 at 19:24

Your Answer

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

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