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) »
  • Listing Values of a Multi-select Custom Field
Pages: [1]

Author Topic: Listing Values of a Multi-select Custom Field  (Read 1091 times)

jhofer

  • I’m new here
  • *
  • Posts: 23
  • Karma: 0
  • CiviCRM version: 3.x
  • CMS version: Drupal 6.x
  • MySQL version: 5.x
  • PHP version: 5.x
Listing Values of a Multi-select Custom Field
March 14, 2012, 11:50:14 pm
Been hitting my head against the wall here... feels like I'm so close yet so far.

Trying to create a simple listing of all of the selected options in a custom field via the API.  I'm able to display custom text fields no problem but I'm having trouble dealing with the array to find/store/display a list of the multi-select data.  Here's what I'm doing:

Quote
$params = array( 'entity_id' => $profile_id,
'version' => 3,
'return.bhc:BHC_Region' => 1, );
$fields = civicrm_api('CustomValue','Get',$params);

foreach($fields as $item){
   echo "$item<br />\n";
   }     

I know I'm missing a step here.  Here's what I get:

Quote
0
3
1
109
Array
Array ( [is_error] => 0 [version] => 3 [count] => 1 [id] => 109 [values] => Array ( [109] => Array ( [entity_id] => 10620 [latest] => Array (  /[0] => 9 ) [id] => 109 /[0] => Array ( /[0] => 9 ) ) ) )

(added the / marks to diplay the brackets and 0s correctly]
Can anyone help me?  I believe this has to do with chaining?

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Listing Values of a Multi-select Custom Field
March 15, 2012, 12:15:12 am
What's the profileid?

I'd suggest you to use the api explorer (at /civicrm/api/explorer on your install) and try CustomValue Get and start adding params on the line.

And use var_export or print_r to see what's in $fields, the result is easier to see

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

jhofer

  • I’m new here
  • *
  • Posts: 23
  • Karma: 0
  • CiviCRM version: 3.x
  • CMS version: Drupal 6.x
  • MySQL version: 5.x
  • PHP version: 5.x
Re: Listing Values of a Multi-select Custom Field
March 16, 2012, 01:29:29 am
The profileid in which the multiselect field resides is 9.  Not sure how I would use profileid to call the field's values...

I was able to use explorer's CustomValue to pull all of the custom values for a specific entity record but when I tried to narrow it down to just the values in my custom id 105... no cigar...

entity=CustomValue&action=get&entity_id=10620&id=105

... just provided the full listing of custom values for that entity_id. The id=105 that I'm interested in returning was part of this list:

Quote
"105":{
         "entity_id":"10620",
         "latest":["5","1"],
         "id":"105",
         "0":["5","1"]

Its the last line that contains the ids to the multi-select custom values that I want to list.

I will continue to play with explorer... 1:30am must go to sleep now!
« Last Edit: March 16, 2012, 01:32:14 am by jhofer »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Listing Values of a Multi-select Custom Field

This forum was archived on 2017-11-26.