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 Import (Moderator: Yashodha Chaku) »
  • Import with shared household address via GUI
Pages: [1]

Author Topic: Import with shared household address via GUI  (Read 2109 times)

ayduns

  • I post occasionally
  • **
  • Posts: 64
  • Karma: 6
    • Squiffle Consulting
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7
Import with shared household address via GUI
July 25, 2013, 03:39:01 pm
Importing contacts sharing an address with a household is not easily supported by the GUI and comments on the forums often suggest using custom scripts.  These notes describe a GUI approach that worked for me.

Before importing anything, clean up the data as much as possible.  If you haven’t discovered OpenRefine (openrefine.org) go look now. Its ability to work with rows and records (multiple rows with a common field) makes it very flexible to manipulate individuals and households.
 
My data already had each contact assigned to a ‘family group’ equivalent to a household.  I created 2 csv files of households and individuals.  Each entry in the households file should include the household name and the address fields.  Each entry in the individuals file should include the household name and other fields not shared with the household.

Use the import wizard to create the new set of households.

Now we want to import the individuals file and use the “Master Address belongs to” field. It would be simple if this were expecting another contact’s name and address type (eg Smith Household, Home address) - but instead it needs an address id, and finding the right value takes us a little more ‘off piste’.

I don’t see an easy way to get that via the civi GUI, but it can be pulled directly from the database. Since we are doing this with GUIs, fire up phpmyadmin, select the civicrm database, click the SQL tab and run:

Code: [Select]
SELECT civicrm_contact.display_name, civicrm_address.id, civicrm_address.street_address, civicrm_address.city, civicrm_address.postal_code
FROM civicrm_contact, civicrm_address
WHERE civicrm_contact.contact_type = "Household" and civicrm_address.contact_id = civicrm_contact.id

(The display_name and id in the select clause are required, the others are optional - see the note below.)

Use the Export link to download the file listing all the households with their name and the address id.  (If you have multiple addresses per household then you probably need additional Where clauses to select the right address.  My households only have one address.)

Now we need to enhance the import file and include the relevant address id from the SQL query. One option is to use the vlookup spreadsheet function.  Arrange your data in a spreadsheet with two tabs: one with the existing import data for individuals, the other with the household name to address id mapping.  Then add a column on the individuals tab with a formula something like =vlookup(A2,Sheet2.A2:E500,2,0) … Assuming your household name is column A and your mapping data is A2:E500.  The result should be the relevant address id.  Now do the same to lookup the street address, city and postal code.

Check for any lines where vlookup has failed.  Correct or remove them otherwise the import to Civi will fail.  Then save it as a csv.

Use the Civi import wizard and map the address id column to “Master Address belongs to Home” and the other address fields as usual.

Once the import has finished, you should find the individuals are correctly mapped to the households.  One extra bit of CiviMagic is that when you share an address with a household, it automatically creates a ‘Member of Household’ relationship.

One less magic thing is that when a shared address is imported with just the address id, Civi shows that the individual shares an address with the household but does not show the actual address.  However, when the household address is updated it will then be copied to the individual and then display as expected.  A work around for this is to import address fields as well as the shared address id - hence the street_address, city, postal_code in the SQL query and the individual import file.

Hope this helps someone!

gibsonoliver

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 2
    • Northbridge Digital
Re: Import with shared household address via GUI
June 18, 2014, 10:16:49 am
Thanks ayduns

This helped me

Oliver
Oliver Gibson, Northbridge Digital

Birgit Pauli-Haack

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • Making the web suck less....
    • Tech4Good SWFL
  • CiviCRM version: 4.6
  • CMS version: WordPress
  • MySQL version: 5.1.58
  • PHP version: 5.4
Re: Import with shared household address via GUI
August 01, 2014, 11:47:36 am
Still works like a charm - 4.4.5 - Thanks a million, @ayduns
Connect @t4gswfl #nptech @bph @paulisystems

biologyben

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 2
  • CiviCRM version: 4.5.3
  • CMS version: Wordpress 4.0
Re: Import with shared household address via GUI
November 08, 2014, 10:35:37 pm
Brilliant - Awesome instructions!  ;D  working with 4.5.3

Why is this type of info not in the book or wiki? ???
« Last Edit: November 08, 2014, 10:42:38 pm by biologyben »

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: Import with shared household address via GUI
November 09, 2014, 06:54:53 am

The wiki is community editable. Please take the time and add this information to the wiki to avoid other folks asking the same question:)

thanx

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

biologyben

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 2
  • CiviCRM version: 4.5.3
  • CMS version: Wordpress 4.0
Re: Import with shared household address via GUI
November 09, 2014, 08:00:01 pm
Done - I barely know what I'm doing, so someone should probably check that I didn't screw that up...

http://wiki.civicrm.org/confluence/display/CRMDOC/Importing+Data+-+Notes

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • Import with shared household address via GUI

This forum was archived on 2017-11-26.