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) »
  • Update Primary Email
Pages: [1]

Author Topic: Update Primary Email  (Read 704 times)

Tiffani Chin

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.30
  • PHP version: 5.3.17
Update Primary Email
August 23, 2012, 05:53:53 pm
Question that I can't seem to solve:

We have a new set of emails for a big batch of our contacts (downloaded from a survey they just completed for us).  Some of these "best emails" are identical to emails that we already have for them, others are new.

The people in our databases have various different email locations set to "is_primary" so I can't upload the new emails into one location.

Is there any way to do an upload that will set the newly uploaded emails to primary?

I've tried batch update, which does put the new email into the primary spot, but it does so by replacing the email that is already in that location.

So, if a user gives me his "best email" as his work email, but his old "best email" was home, if I batch update into primary, it replace the old home address with the new work address.  This gets the right email into "primary" but doesn't seem like the idea solution.

Would appreciate any wisdom you might have.

Thanks!
-tiffani

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: Update Primary Email
August 23, 2012, 06:38:09 pm
Hi Tiffani,

This has come up before, and unfortunately, there's no way to do this through the UI.

If you have to do this, the best way might be with SQL.  My general approach would be as follows.  Note that I HAVE NOT TESTED this SQL, so a) test on a backup (always a good idea!) and b) be prepared to tweak:
* Put your site in offline mode if there's a possibility anyone will be adding/editing e-mail addresses while this is in progress.  Let's say in this example that it's 100.
* Look at your civicrm_email table, note the maximum value in the `id` field.
* Import addresses in the usual way.
* Unset the is_primary field on any e-mails that have a contact_id that matches the new addresses:
UPDATE civicrm_email AS a, civicrm_email AS b ON `a`.`contact_id` = `b`.`contact_id` SET `a`.`is_primary` = 0 WHERE `b`.`id` > 100;

* Update all the new e-mails to be primary:
UPDATE `civicrm_email` SET `is_primary` = 1 WHERE `id` > 100;

Hope that at least gets you in the right direction!

Jon
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

Tiffani Chin

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.30
  • PHP version: 5.3.17
Re: Update Primary Email
August 27, 2012, 10:19:57 pm
Jon,

This is a great idea.  I totally forgot that Civi assigned a new email ID to each email (regardless of which user the email is attached to).

We will give this a shot.  We've been messing with the database anyway (trying to rotate email addresses) so this feels very doable.

I post the results.

Thank you!
-tiffani

Tiffani Chin

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.30
  • PHP version: 5.3.17
Re: Update Primary Email
September 26, 2012, 07:59:14 pm
Just as an update: we tried a similar process:

We didn't really want to mess with primary emails (because we wanted to retain that info).
So, we set everyone's primary to their "bulk email"
Then, in the database, we marked everyone's "secondary" email as "bulk mail" and put all of the other emails "on hold" so that people without secondary emails would not get duplicate emails.

The process worked BUT... tokens for custom fields did not come through on these second emails (nor on the third emails we sent, after setting the tertiary emails to "bulk mail" and putting the rest on hold.

I don't know if messing with the database caused this problem -- but it was a critical problem for our purposes.

Now.. I could have sworn that I read on this forum that Civi 4.2 would allow us to send bulk mails to all emails... and now I can't find that post.  Am I crazy or did someone say that?

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Update Primary Email

This forum was archived on 2017-11-26.