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) »
  • Best Practice Question: Updating Street Address
Pages: [1]

Author Topic: Best Practice Question: Updating Street Address  (Read 1391 times)

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Best Practice Question: Updating Street Address
May 21, 2010, 10:09:32 am
Recently did a postal mail send.  Got a report back from the mailing company in Excel format with names, old addresses that don't work, and new addresses that do work.  Email or other unique identifier is not available.

This report is almost 1000 records, and is rather intimidating to do by hand.

Without an external identifier in this report, or any kind of email address, just a first name and last name, it seems like using this Excel to import/update would just create a lot of duplicates. 

Any other ideas for automation to save us all this data entry ?

Try CiviTeacher: the online video tutorial CiviCRM learning library.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Best Practice Question: Updating Street Address
May 21, 2010, 11:22:12 am
My choice would be to write a php script to compare names and old addresses, and update the location file with the new adresses. The only other option I can see is fiddle about with MySQL writing a procedure that would do the same, but that would not be my choice. Would you have enough knowledge to create such a script?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: Best Practice Question: Updating Street Address
May 21, 2010, 11:23:55 am
two suggestions:

1. Use the API to query the system and retrieve the external ID for all names. This will probably give you a match for a large percentage, the rest will need to be handled manually. Then use import :)

2. The second suggestion is basically the same as the first, but do the update of the new address at the same time (since you are already half way there). Will be a great example of using the API to do stuff

please share your code if you go with the above path.

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

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Best Practice Question: Updating Street Address
May 21, 2010, 03:53:05 pm
Hi guys, thanks for your replies, I have explored my options.

In the end, I ended up not using any PHP (the API or otherwise), cause I didn't see a clear way to join sets of data (one without Internal ID and one with) using PHP scripting, APIs or modules.   I found the API to be unnecessary and burdensome, I'm sorry if I have dissapointed you, but those were my thoughts.  When I know exactly what to do in MySQL, and how to do it, I tend to avoid spending a large amount of extra time involving PHP to accomplish my goals.

I set up a couple sandbox mySQL tables locally where I did some basic work.  The entire process was simple, required only phpMySQLAdmin and CiviCRM built-in Import and export features, and took me just over 1 hour.

Tables contained:
1. Used existing CiviCRM Export feature....Exported data from CiviCRM, including Names, Address fields, and most importantly Internal ID
      ~15000 rows named this table civi
2. Data from our mail vendor which includes Name, Address (old and new) but no Internal ID  ~2000 rows named this table returns

I updated returns table #2 based on a set of matching criteria:
   a. name
   b. city
   c. state
   d. zip

This was enough to match 98% of all Contacts, where I then gathered the ID from one table and updated it into the other table

This query tests my data and my theory:
Code: [Select]
SELECT DISTINCT returns.Name, civi.Internal_ID, returns.Current_Delivery_Address
FROM `returns` JOIN `civi` ON
returns.Name = CONCAT(civi.First, ' ', civi.Last) AND
returns.Previous_City = civi.City AND
returns.Previous_State = civi.State AND
returns.Previous_ZIP = civi.Postal

This was the query that did the heavy lifting and actually made the updates:
Code: [Select]
UPDATE `returns` SET returns.Internal_ID = (
SELECT civi.Internal_ID FROM `civi` WHERE
returns.Name = CONCAT(civi.First, ' ', civi.Last) AND
returns.Previous_City = civi.City AND
returns.Previous_State = civi.State AND
returns.Previous_ZIP = civi.Postal
)

This query double checks my work:
Code: [Select]
SELECT returns.Name as ReturnsName, CONCAT(civi.First, ' ', civi.Last) as CiviName,
returns.Internal_ID, civi.Internal_ID
FROM
`returns` JOIN `civi` USING (Internal_ID)

Once my data was ready, I exported it from mySQL using phpMySQLAdmin as a CSV, and then mapped and imported this data into CiviCRM using the CiviCRM Import tool, careful to map to External ID set my duplicates to "update".    I found that the Import tool froze if I imported more than 1000 records, so I split my import in half.  I find this is a best practice when importing into Civi anyway
« Last Edit: May 21, 2010, 03:57:42 pm by Stoob »
Try CiviTeacher: the online video tutorial CiviCRM learning library.

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: Best Practice Question: Updating Street Address
May 21, 2010, 04:24:50 pm

hey no worries about that. but thanx for documenting your process. this will allow other folks to follow your example and do something similar

at some point, someone will write a magic script to take care of this

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • Best Practice Question: Updating Street Address

This forum was archived on 2017-11-26.