CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Search for all Individuals Related to Member Organizations
Pages: [1]

Author Topic: Search for all Individuals Related to Member Organizations  (Read 2880 times)

ds505

  • I post occasionally
  • **
  • Posts: 40
  • Karma: 3
Search for all Individuals Related to Member Organizations
September 06, 2007, 01:12:41 pm
We're working with a nonprofit client that has Organization memberships. They also capture Individuals and relate them as Employees of the Organization.

What the client would like to do is an advanced search that would list all of the Organization Memberships and then all the Individuals who are related to those Organizations with "Employee of". We've tried a variety of searches as well as Search Builder and can't seem to get it to work.

Has anyone needed anything like this? It seems like we would need to find the Organization Members first and then perform a second search that looks at the first one to get the Individuals. We'll probably have to do this as a MySQL query, but any thoughts or hacks within CiviCRM would be fabulous.

Thanks!
Data-Scribe(r)
http://www.datascribe.biz

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Search for all Individuals Related to Member Organizations
September 06, 2007, 02:44:43 pm

This would be a really cool feature to have in CiviCRM at some stage :) Driving a future search based on the results of a past search. In your case it would be:

Give me all the Contacts who have an "Employee of" Relationship with all the Contacts from the membership search. I suspect this could be done based on adding a "inclusion / exclusion" group clause to search. Good food for thought for the future

In your case, i suspect a custom query might be the easiest. You can use the mysql query log to extract the queries that civicrm generates and use them. You will need to generalize the queries a bit since CiviCRM relationship queries are name based rather than contact id based. This is also a good use case for where "exposing" a sql interface to the user will make things better in the long run

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

ds505

  • I post occasionally
  • **
  • Posts: 40
  • Karma: 3
Re: Search for all Individuals Related to Member Organizations
September 08, 2007, 06:57:44 pm
Hi Donald,
Thanks so much for the response. We hadn't come across the mysql queries on the Wiki (http://wiki.civicrm.org/confluence/display/CRMDOC/Useful+SQL+queries for others' reference).

We'll work on this and will post the solution soon.

Thanks!
Data-Scribe(r)
http://www.datascribe.biz

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Search for all Individuals Related to Member Organizations
September 10, 2007, 10:14:19 am
This could also be implemented as a "report" in the CiviReport library. I think it would potentially be useful to others - and hence a cool contribution. Check out the CiviReport section on the wiki for an intro/overview...

http://wiki.civicrm.org/confluence/display/CRMDOC/CiviReport
Protect your investment in CiviCRM by  becoming a Member!

mcsmom

  • I post frequently
  • ***
  • Posts: 266
  • Karma: 23
    • Official Joomla! Book
  • CiviCRM version: 4 and 3.4
  • CMS version: Joomla!
Re: Search for all Individuals Related to Member Organizations
September 14, 2007, 05:15:53 am
Yes, yes!

Actually, I have some mysql queries that will produce some of these.

Unfortunately, right now the simplest thing  to do if you have end users trying to pull the information is to make a custom field that reproduces the information.

Here's for individuals and households

DROP TABLE IF EXISTS relationshipa;
DROP TABLE IF EXISTS relationshipb;
DROP TABLE IF EXISTS all_relationships;
CREATE  TABLE relationshipa as
 SELECT r.contact_id_a AS contact_a,r.id AS relationship_id,r.relationship_type_id AS rel_type,c.id AS contact_id,c.sort_name AS namea
 FROM civicrm_relationship AS r, civicrm_contact AS c
 WHERE  r.contact_id_a=c.id  AND r.relationship_type_id=7 ;

 
CREATE  TABLE relationshipb as
 SELECT s.contact_id_b AS contact_b,s.id AS relationship_id,s.relationship_type_id AS rel_type,d.id AS contact_id,d.sort_name AS nameb
 FROM civicrm_relationship AS s, civicrm_contact AS d
 WHERE  s.contact_id_b=d.id AND s.relationship_type_id=7 ;


CREATE  TABLE all_relationships as
SELECT h.relationship_id AS r_id_a,h.rel_type AS rel_type_a,j.relationship_id AS r_id_b,h.namea AS name_a,j.nameb AS name_b
FROM relationshipa AS h,relationshipb AS  j
WHERE  h.relationship_id=j.relationship_id;


SELECT k.r_id_a AS r_id_a,k.r_id_b AS r_id_b,k.name_a as name_a,k.name_b AS name_b,k.rel_type_a AS reltype,
                             l.id AS reltype_id,l.name_a_b AS rolenamea,l.id AS reltype_id,l.name_b_a AS rolenameb
FROM  all_relationships AS k,civicrm_relationship_type AS l
WHERE k.rel_type_a=l.id
order by k.name_b


obviously change lines 7 and 13 for the relationship you want.

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Search for all Individuals Related to Member Organizations
September 17, 2007, 07:26:39 am
I have a need for this functionality too, and thought CiviCRM already provided this functionality. What made me think this is the option in membership types to define the relationship type. The field hint says:

Code: [Select]
Select relationship type for this membership type. EXAMPLE: Select 'Household Member is' for memberships where the direct member is a Household and you want all Household Members to be automatically granted memberships.
I would think what this means is that individuals related to a parent organization, for which the parent organization is the member, are considered members. Therefore if I search for all indivs in a given membership category (where the membership category applies to an org type), I get my list.

But it doesn't work. So my question is, what's the purpose and function of the membership type > relationship type field?

-Brian
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Search for all Individuals Related to Member Organizations
September 17, 2007, 11:58:19 am
Brian - This feature should work as you've described - assuming that you've set up the Membership Type with the approporiate relationship - and that relationships is established between the member organization and the individuals. You can verify your setup by creating a relationship (e.g. Employee of) of that type between a member org and an individual. Then checking the Memberships tab under that individual. It should show a "non-editable" membership.

If you've got things setup correctly and not getting the expected behavior, please replicate on the demo and post your results here.

thx!
dave
Protect your investment in CiviCRM by  becoming a Member!

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Search for all Individuals Related to Member Organizations
September 18, 2007, 05:42:17 am
Dave,
I set it up on the Joomla demo. Here's what I did, and what you want to look at:

ACME Association: membership organization
Relationship Demo Membership: membership type; fixed period; relationship: employee of (thus all employees should be considered members when the parent org is defined as a member)
ABC Company: organization which becomes a member of ACME Association
Brian: individual who is an employee of ABC Company

As I understand it, there should be an uneditable membership record for Brian, since his company (ABC Company) is a member of ACME Association with the appropriate membership type/relationship type.

But it doesn't seem to work. Nothing shows up in Brian's membership record.

-Brian
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Search for all Individuals Related to Member Organizations
September 18, 2007, 06:05:02 am
Ok, ok, ok. Perhaps I checked my brain at the door.

I just played around some more with the demo, and created a second membership type with identical settings, but used the reverse relationship. Initially I used "employee of." In the second membership type I used "employer of" -- just to see if it was my logic that was messed up. And it was.

However, in my defense, the description for the relationship type field is confusing. It reads:

Code: [Select]
Select relationship type for this membership type. EXAMPLE: Select 'Household Member is' for memberships where the direct member is a Household and you want all Household Members to be automatically granted memberships.
I equated "household member is" with "employee of" because both were describing the individual, and I wanted the same scenario described in the description-- all employees/members of an organization/household are considered members.

So sorry for the false alarm.

For the sake of the early posters in this thread --
I believe that setting this up correctly will address the original posters (and my) dilemma. When I go to advanced search now and do a search for individuals, with a membership type of the category desired, I receive all the employees of the organization which is a member of that type.

One other comment --
The relationship type field can't be edited through the CiviCRM interface. But it can be changed by getting into the MySQL db and looking at the civicrm_membership_type table-- relationship_type and relationship_direction fields. If you did what I did, you can switch the data in the relationship_direction field from a_b to b_a (or vice versa). I've tested it on mine and that fixes things.

Sort of. It fixes things moving forward, but not for existing data. Anyone with insight on how I take my 1000+ pre-existing membership records and populate the relationships down to the individuals of org, please don't hesitate to chime in!

thanks,
Brian
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Search for all Individuals Related to Member Organizations
September 18, 2007, 06:35:36 am
Dave,
You may know this --
On my last question re: how to update all my records so that the individual relationships are built --
I don't have the membership status update cron job setup yet. But am curious -- will that cron rebuild my data based on the relationships? If so, that would be great. Very "self-correcting."
-Brian
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Search for all Individuals Related to Member Organizations
September 18, 2007, 07:37:56 am
Sorry for all the posts, but I answered my own question.
Yes, the cron job does repopulate all the related records, and thus self-corrects the relationship mistake. Excellent!
-Brian
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Search for all Individuals Related to Member Organizations
September 18, 2007, 05:55:15 pm
Quote from: lcdweb on September 18, 2007, 06:05:02 am
However, in my defense, the description for the relationship type field is confusing. It reads:

Code: [Select]
Select relationship type for this membership type. EXAMPLE: Select 'Household Member is' for memberships where the direct member is a Household and you want all Household Members to be automatically granted memberships.
I equated "household member is" with "employee of" because both were describing the individual, and I wanted the same scenario described in the description-- all employees/members of an organization/household are considered members.


Brian - I agree that selecting the correct relationship type is confusing. I've added a dedicated HELP section to this form field in the upcoming 1.9 release which provides examples for what I think will be the most common uses (Household -> Household Member, Organization -> Employee, Parent -> Child). Hopefully that will make it easier for folks going forward.
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Search for all Individuals Related to Member Organizations

This forum was archived on 2017-11-26.