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) »
  • How to sell all "Work" addresses to be Primary at once?
Pages: [1]

Author Topic: How to sell all "Work" addresses to be Primary at once?  (Read 1379 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
How to sell all "Work" addresses to be Primary at once?
February 17, 2009, 03:29:46 pm
Hello thanks for reading --  as our database has grown, we have three used addresses for our contacts:

1) Work
2) Home
3) Other

Over time, some contacts have coded their Work to be primary, and some Home, and some Other.  We would like to reset all contacts so that Work is checked as the "primary"?

I am familiar with MySQL and can run queries if this is the easiest way, or if there is a way to do it through the Admin interface that's fine too.

Please let m know how I could accomplish this.

Thanks,
Stuart


Try CiviTeacher: the online video tutorial CiviCRM learning library.

Sunil

  • I post frequently
  • ***
  • Posts: 131
  • Karma: 23
  • The community around a product more important than the product itself?
    • CiviCRM
Re: How to sell all "Work" addresses to be Primary at once?
February 18, 2009, 05:12:26 am
Hi,

is every contact have max one location type? ( e.g. contact don't have work and Home Location Type at time )
Then you can run MySQL queries easily. by just changing the llocation_type_id  in following tables
 civicrm_address, civicrm_phone, civicrm_im, civicrm_email, civicrm_openid

sunil

The community around a product more important than the product itself?

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: How to sell all "Work" addresses to be Primary at once?
February 18, 2009, 10:28:41 am
Many contacts have both a Work and Home address.  Some have 3: Work, Home, Other.  The primary could be marked Work, Home, or Other.  It's all mixed up.

How can I set them all to "Work" as primary, without doing it manually 200+ times?

Any ideas?  Thanks!!!!!!!!  :) :)
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: How to sell all "Work" addresses to be Primary at once?
February 18, 2009, 10:49:58 am

you will need to write a php/sql script to do the needful. or if u r really really good at mysql  you can potentially do this in sql

you will need to fix the tables sunil mentioned


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: How to sell all "Work" addresses to be Primary at once?
February 18, 2009, 09:25:46 pm
Hi thanks for the information.

Here are the queries I used just so hopefully it can help someone else.

Step 1:
Identify the "location_type_id" of the location you want to use for the primary for everyone.  For me, it was 2.  So if you are using these queries use whatever location_type_id# is appropriate for you and substitute the number in instead of 2.

Step 2:
Run each of these queries on the following tables: civicrm_address, civicrm_phone, civicrm_im, civicrm_email, civicrm_openid
this query sets all the non-desired location_type_id to 0 or not primary
Code: [Select]
UPDATE civicrm_address SET is_primary=0 WHERE location_type_id<>2;
this query sets all the desired location_type_id to 1 or primary
Code: [Select]
UPDATE civicrm_address SET is_primary=1 WHERE location_type_id=2;

Step 3
And finally, since a small number of our contacts did not have a work address at all (id #2 in my case), and therefore had no primary address after the above queries were run -- this query identified those people by name and contact_id.  Because we had only a dozen of these situations in our whole database we decided to deal with this manually, although if you wanted you could use the following query as a subquery in a larger update query;

Code: [Select]
SELECT DISTINCT a.contact_id, c.first_name, c.last_name FROM civicrm_address AS a JOIN civicrm_contact AS c ON a.contact_id=c.id where (SELECT contact_id FROM civicrm_address AS b WHERE location_type_id=2 AND a.contact_id=b.contact_id) IS NULL AND a.contact_id IS NOT NULL AND c.last_name IS NOT NULL;
Try CiviTeacher: the online video tutorial CiviCRM learning library.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • How to sell all "Work" addresses to be Primary at once?

This forum was archived on 2017-11-26.