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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Search by custom data in address API
Pages: [1]

Author Topic: Search by custom data in address API  (Read 597 times)

nickholden

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 1
  • CiviCRM version: 4.4.1
  • CMS version: Drupal 7
  • MySQL version: 5.5.32
  • PHP version: 5.4
Search by custom data in address API
September 11, 2013, 08:21:58 am
We have custom data loaded against addresses (a site identifier, essentially) which I want to be able to search for using the API. When the address is set to is_primary = 1 then the Contact API will allow me to do a get which uses the custom_XX form to include the custom data as a search parameter. But if the address is for a branch location (i.e. not a primary address for a contact) then the search fails.

The Address API doesn't seem to allow the use of custom data for searching, and the custom_value API needs the entity ID in order to return the custom value, whereas I want to supply the custom value in order to return the entity ID (or, in fact, the contact who is linked to the entity ID, since the entity in this case is the address).

Is there a better way to do this than to force all the branch addresses to also have is_primary set to 1? I know this makes no sense, but it seems to be possible to have more than one is_primary address, and if we do that, then searching for any of the main or branch site identifiers will return the same contact ID. Since this is the behaviour I want, what's the downside of doing this?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Search by custom data in address API
September 13, 2013, 01:06:17 pm
It should not be possible for a contact to have more than one is_primary address. We should make it possible for address to search by custom data (patch welcome yada yada yada) but - have you tried passing the address custom field to contact.get as a search criteria? Contact.get does all sorts of wild & undocumented things - although we recommend you submit a unit test to look in undocumented functionality you are using
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

nickholden

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 1
  • CiviCRM version: 4.4.1
  • CMS version: Drupal 7
  • MySQL version: 5.5.32
  • PHP version: 5.4
Re: Search by custom data in address API
September 19, 2013, 06:25:37 am
Thanks, Eileen. As I understand it, the GUI does impose the restriction on not more than one is_primary address, but the database doesn't, so it is possible to edit the database, but editing the address at a later time in the GUI would result in the is_primary flag being reset.

Yes, I had tried the approach you suggest. Contact.get does return results but only from those addresses which are is_primary = 1. Hence why I was contemplating database butchery.

In the end, my better angels won out. I settled on pulling all the addresses from the database into an array, and then searching the array for the custom data. Not pretty, and not very scalable, but it works for now.

In principle I'd be happy to work on a patch for the Address API, but it's a steep learning curve and an awesome responsibility.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Search by custom data in address API
September 19, 2013, 12:31:48 pm
If you have more than one primary address for a contact you may find report totals are incorrect.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

nickholden

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 1
  • CiviCRM version: 4.4.1
  • CMS version: Drupal 7
  • MySQL version: 5.5.32
  • PHP version: 5.4
Re: Search by custom data in address API
September 20, 2013, 07:23:19 am
That sounds like a good enough reason not to do it! Thanks.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Search by custom data in address API

This forum was archived on 2017-11-26.