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) »
  • Get contact with custom field option='region1'
Pages: [1]

Author Topic: Get contact with custom field option='region1'  (Read 1060 times)

bouton

  • Guest
Get contact with custom field option='region1'
November 30, 2011, 07:12:31 am
I have a custom field (Regions) which is a set of multiple choice checkboxes.

Using the API how do I return all contacts with checkbox "region1" checked?

I got 'custom_15' by looking in the db in civicrm_custom_field and getting the id of 'Regions' which is the grouping. I want one region from regions. ie region1 which is one value of the group regions

Reading the docs ($param['custom_N'] => 'value';) I thought that I would do it like
Code: [Select]
$params = array(
'version' => 3,
'sequential'=>'1',
'json'=>'1',
'contact_type' => 'Organization',
'custom_15'=>'region1'
);
$results=civicrm_api("Contact","get", $params);
I think its because it is a checkbox. I've tried to find api examples - but no luck? Any suggestions?
Thanks!
« Last Edit: December 01, 2011, 01:30:37 am by bouton »

bouton

  • Guest
Re: Get contact with custom field option='region1'
December 01, 2011, 01:30:15 am
I changed it to array and got come thing back - but not filtered still. Will keep researching.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Get contact with custom field option='region1'
December 01, 2011, 06:17:59 am
How is defined custom? is this part of a multiple values set or a single one?

How does it look like if you contact.get return=custom_15 ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

bouton

  • Guest
Re: Get contact with custom field option='region1'
December 01, 2011, 09:19:06 am
Hello Xavier
Thanks. Yes, the custom field is a multiple values set (multiple choice checkboxes).
I followed your suggestion
Code: [Select]
$params = array(
'version' => 3,
'json'=>'1',
'sequential'=>'1',
'contact_type' => 'Organization',
//'custom_15'=>'region_1'
'return'=>'custom_15'
);
$results=civicrm_api("Contact","get", $params);
I get ALL contacts returned, those with and without custom_15 set.
And when custom_15 is returned it an array with those items which were ticked for that contact. But there is no filtering  ie I want only those contacts where custom_15 contains 'region1'

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Get contact with custom field option='region1'
December 01, 2011, 10:09:50 am
Hi,

if you add a param custom_15= array (as returned) is should work.

Can you create on demo the same custom as you have?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

bouton

  • Guest
Re: Get contact with custom field option='region1'
December 02, 2011, 02:46:45 am
Nope, no luck.
I have set up a similar situation on demo.
Custom group = testsuite
custom field regions with multiple choice checkboxes for North, South etc. Note I did a micuter of hyphens and underscores in values to see if that was the issue.
Entered 2 contacts
http://drupal.demo.civicrm.org/civicrm/contact/view?reset=1&cid=136 with a couple of checkboxes checked
http://drupal.demo.civicrm.org/civicrm/contact/view?reset=1&cid=137 with one checkbox checked.

Thanks


bouton

  • Guest
Re: Get contact with custom field option='region1'
December 06, 2011, 07:52:53 am
I had put these up but they seem to have disappeared off demo. Did you have a chance to look or should I do it again? Thanks.

bouton

  • Guest
Re: Get contact with custom field option='region1'
December 07, 2011, 09:44:18 am
Still unable to get this to work.
Using the api calls above I get all contacts, rather than a filtered list on the custom field.

I have again added custom field of a multiple checkbox set
UK GOR regions is the set and regions is the multiple checkbox with values North, South, East, West.
I have added two contacts with some multiple values set.
http://drupal.demo.civicrm.org/civicrm/contact/view?reset=1&cid=123
http://drupal.demo.civicrm.org/civicrm/contact/view?reset=1&cid=124

Wonder if you could see how, using the api, I can return just those contacts that have Region=South checked.
Thanks
-K

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Get contact with custom field option='region1'

This forum was archived on 2017-11-26.