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 »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • linking individual and organization records - a better way?
Pages: [1]

Author Topic: linking individual and organization records - a better way?  (Read 3101 times)

thebenedict

  • Guest
linking individual and organization records - a better way?
April 02, 2008, 12:29:37 pm
A problem I'm having came up a few months ago:

Quote from: Dave Greenberg on November 23, 2007, 10:27:14 am
You can also enter the Organization name in the Current Employer field when creating the Individual. This will create the employer-employee relationship automatically. HOWEVER, this feature requires that the employer name be entered exactly - and doesn't handle multiple employee organizations with the same name nicely (there's no mechanism for specifying the correct one).

I'm letting users create an individual record for themselves as they sign up for a mailing list through a profile form (I'm not using the built in subscription form because there's other info. I want to collect at the same time). Since some users will belong to an organization that's already registered, it's important that they be given the option of associating their individual record with their organization's record via an 'employee of' relationship. What would be involved in providing a drop down menu of organization records to choose from or autocomplete for the field? Where would I start? I think I would end up with a lot of duplicate organizations if I allowed free text entry because some wouldn't enter the org. name just right.

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: linking individual and organization records - a better way?
April 02, 2008, 01:07:13 pm

You will have to tweak the code at: CRM/Core/BAO/UFGroup.php, function buildProfile (line 1320)

I'm pretty sure the field name is organization_name and you should make it conditional based on the profile type being Individual.

Chat with us on IRC if you need help. That code requires a fair amount of cleanup (IMO)

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

thebenedict

  • Guest
Re: linking individual and organization records - a better way?
April 02, 2008, 06:42:51 pm
Great. I added this to CRM/Core/BAO/UFGroup.php, function buildProfile and it seems to work as advertised:

Code: [Select]
        } else if ($fieldName == 'organization_name' && isset($form->_gid) && $form->_gid == '1') {
            $orglist=array("" => "-- Select --");
            $query = "SELECT `organization_name` FROM `civicrm_contact` WHERE `organization_name` IS NOT NULL";
            $dao = CRM_Core_DAO::executeQuery( $query, CRM_Core_DAO::$_nullArray );
            while ( $dao->fetch( ) ) {
               $orglist[$dao->organization_name] = $dao->organization_name;
            }
            $form->add('select', $name, $title, $orglist );

I also had to make _gid a public variable in CRM/Profile/Form.php.

Thanks again for the help lobo... support here is impressive.

RTPUK

  • Guest
Re: linking individual and organization records - a better way?
April 11, 2008, 07:59:05 am
Hi I am not much of a programmer but I saw this posting and wanted to achieve something similar.  My company needs to link an individual contact to a company i.e. current_employer = organization_name.  We need this for two reasons.

Firstly just as thebenedict wants to use the drop-down list to ensure that if a company already exists it can be easily selected. 

Secondly so that when we export an individuals details for use in a mail merge we can get their employer's address into the export file.

I've tried to use the code posted above and use it in the CRM/Core/BAO/UFGroup.php with no luck but if there is an easier solution as well that would be great.  Any help would be greatly appreciated


thebenedict

  • Guest
Re: linking individual and organization records - a better way?
April 11, 2008, 08:17:29 am
RTPUK,

Hard to tell what's going on, but:

-I am using Drupal 5.7 and CiviCRM 2.0b3

-You have to make _gid public in CRM/Profile/Form.php:

Code: [Select]
    /**
     * The group id that we are editing
     *
     * @var int
     */
    public $_gid;

otherwise buildProfile can't make use of _gid.

If you do find an easier solution, let me know:)

RTPUK

  • Guest
Re: linking individual and organization records - a better way?
April 14, 2008, 03:17:45 am

Thanks thebenedict for the reply.  I think i'm placing your code in the wrong spot in the build profile code as I have ensure that $_gid is public. This means I always get the error below.

Parse error: syntax error, unexpected T_ELSE in C:\wamp\www\drupal-5.7\sites\all\modules\civicrm\CRM\Core\BAO\UFGroup.php on line 1338

Could you lend me a hand as to where in the build_profile code I should be making the changes?


RTPUK

  • Guest
Re: linking individual and organization records - a better way?
April 14, 2008, 03:31:28 am
Actually got the code in the right spot now, I think as I am no longer getting the error message; however there is no drop-down list to select from.  I have checked the query in phpMySQL and have got the right results.

Can you think of anything that I might have to do yet that I haven't?

Thanks

thebenedict

  • Guest
Re: linking individual and organization records - a better way?
April 14, 2008, 06:26:29 am
Sounds like you probably have the code in the right place. Have you changed the gid == '1' in the first line to the gid of your profile? Mine happened to be 1, but you can get yours from the URL.

RTPUK

  • Guest
Re: linking individual and organization records - a better way?
May 02, 2008, 06:20:51 am
Sorry been a bit slow in working on this. I am not sure what you mean by the gid=1 in my profile? I've just got back on this task and it still seems that i can't get a drop-down list of organisations showing.

everything else seems to be correct. I've set the gid to be public, got the query in the right spot but still can't get it displayed.

help much appreciated

thebenedict

  • Guest
Re: linking individual and organization records - a better way?
May 06, 2008, 02:40:32 pm
The gid in the code has to be the id number of the profile you want the drop down to appear in.

If the trouble is with profile id's, see:
http://wiki.civicrm.org/confluence/display/CRMDOC/Linking+Profiles

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • linking individual and organization records - a better way?

This forum was archived on 2017-11-26.