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 (Moderator: Dave Greenberg) »
  • Relationship Import
Pages: [1]

Author Topic: Relationship Import  (Read 1910 times)

G.Kurt

  • Guest
Relationship Import
February 05, 2008, 07:03:21 am
Hi,

I'm doing my first steps with CiviCRM and tried to import data from a csv file. The import of individuals worked well after a little customizing of the data. But I can't find a way to import the correct relationships of the families.

The csv file brings the following relationship information with it:
Personal_IDFamily_IDFamily_RoleLastnameFirstnameBirthdayetc.Personal-/Family-ID_1Personal-/Family-ID_2Personal-/Family-ID_3Personal-/Family-ID_4Personal-/Family-ID_5Personal-/Family-ID_6
10012100121MillerPeter1970-01-01
10012100131001410015

10013100122SmithKristin1971-02-12
10012100131001410015

10014100123MillerJonathan1996-10-10
10012100131001410015

10015100123MillerJoel1996-10-10
10012100131001410015


[The Personal_ID of the Head of the Household is the same as the Family-ID; the Familiy_Role "1" identifies the husband, Family_Role "2" identifies the spouse, "3" is used for all children.]

Does anyone has an idea how to create the relationships via import?

Thanks for your help!

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Relationship Import
February 06, 2008, 07:21:37 am
The built-in import allows you to import "related contacts" inline. So, when importing Peter Miller, you could include columns for his children's first and last names in the same row. Then map them by selecting "-related contact info-" >> Child of >> First Name, Last Name.

It may be possible to use the
  • "Update if Duplicate" feature to go back and define these on a second pass. I'd first try it with a small sample - and define Head of Household:

* Import a few Household records
* Then re-import existing individuals (head of households) with a column added for Household Name

However,  I have tested this type of update and it might not function as expected. Also, this may be too cumbersome given the structure of your data. It might be better to create a script to do insert the relationships directly via SQL. If you fill the External Identifier (civicrm_contact.external_identifier) field with your Personal_ID value for individuals, and Family_ID for households - you'll have a unique key in the DB to figure out which records need to be connected.
Protect your investment in CiviCRM by  becoming a Member!

G.Kurt

  • Guest
Re: Relationship Import
February 06, 2008, 11:10:51 pm
Hi Dave,

thanks for the quick response. Unfortunatly I'm just an "interested user" - SQL scripts are not in my field. I will look for some SQL documentation how to write a script to insert the relationships directly and connect the records. Although my DB knowledge is pretty small.


Kurt

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
SQL scripts better than APIs ?
February 11, 2008, 01:08:25 am
Hi Dave,

I'm surprised you recommend hammering at the sql level directly from the import script.

I'd rather have started with using Civicrm classes to work at an higher level of abstraction, so it takes care of the functionnal constraints and be sure not to miss a record on some table here and there, and makes it hopefully work better next time there is a new db schema.

Are they limitations on the classes and apis that i'm not aware of so they are unfit for that need ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Relationship Import
February 12, 2008, 08:26:56 am
X - Thanks for chiming in here. I often "assume" that more folks are comfortable w/ SQL scripting than with PHP - hence my initial response. But I completely agree that using the API's to interact with the DB is a much better and safer approach. Our API library is in decent shape - although not as well documented as it should be. There is an API for creating relationships in api/v2/Relationship.php which should do the trick:

civicrm_relationship_create()

... and a set of unit test which give examples of using that API in test-new/SimpleTest/api-v2/RelationshipCreate.php

Note that the unit test directories are not included in the Sourceforge downloads - but are readily available in the SVN repository:

http://svn.civicrm.org/civicrm/branches/v2.0/test-new/SimpleTest/api-v2/
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Relationship Import

This forum was archived on 2017-11-26.