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) »
  • address manipulation
Pages: [1]

Author Topic: address manipulation  (Read 542 times)

mac

  • I post occasionally
  • **
  • Posts: 71
  • Karma: 0
address manipulation
April 09, 2010, 09:46:44 am
We have made the mistake in the past: We have created/imported contacts and didn't assign state/country "information to them". The contacts are related to organizations though that have some information (city, province, country).

So I wrote a query that figures out whether contacts have a relation to an organization (employee relation) and if this organization has an address and the individual itself does not, it copies the address.

Everything seemed to work fine, but for some reason the state/city/province does not appear when we list the contacts and you also can't search by the province for example. When you look at the details of the contact though, the address is shown.

What am I missing? Do I have to modify some other properties/tables?

Code: [Select]
INSERT INTO civicrm_address
(contact_id, location_type_id, country_id, state_province_id, city)
SELECT c.id, location_type_id, country_id, state_province_id, city
FROM civicrm_contact c
  JOIN civicrm_relationship r ON
    r.relationship_type_id = 4
    AND r.contact_id_a = c.id
  JOIN civicrm_address addr ON
    addr.contact_id = r.contact_id_b
    AND addr.location_type_id = 2
WHERE contact_type = 'Individual'
AND NOT EXISTS (
  SELECT 1
  FROM civicrm_address a
  WHERE a.contact_id = c.id
  AND a.location_type_id = addr.location_type_id
);

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: address manipulation
April 09, 2010, 03:34:48 pm

make sure you set the

is_primary

column of the individual civicrm_address to 1 when you do the copy

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

mac

  • I post occasionally
  • **
  • Posts: 71
  • Karma: 0
Re: address manipulation
April 09, 2010, 04:48:55 pm
thanks, that worked.

I initially just tested this with one contact before I posted the question, and it didn't seem to work. But now it works and I can't reproduce why it wouldn't have worked before.

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

This forum was archived on 2017-11-26.