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) »
  • Trouble Getting CustomValues
Pages: [1]

Author Topic: Trouble Getting CustomValues  (Read 901 times)

kengle3

  • I’m new here
  • *
  • Posts: 16
  • Karma: 0
Trouble Getting CustomValues
December 27, 2011, 04:47:18 pm
I'm trying to get some custom values from the Database, but I'm having a lot of trouble trying to get it to work via the API.

From what I understand, all that is needed to get the data is the code below:


$params=array('entity_id' => 1, 'version' => 3, 'return.group_name:field_one' => 1, 'return.group_name:field_two' => 1);
$ret=civicrm_api3_custom_value_get($params);
print_r($ret);

This however breaks the site to a white page.
My best guess is that I'm not using the right 'entity_id'. My current understanding of the entity_id is that it is the contact ID for custom data. I have checked and I am testing the function with a valid contact_id number as an entity_id.

Anyone have any suggestions on what I may be doing wrong?

For reference, the documentation for the API code is below:
/**
 * Use this API to get existing custom values for an entity.
 *
 * @param $params  array specifying the entity_id
 * Optionally include entity_type param, i.e. 'entity_type' => 'Activity'
 * If no entity_type is supplied, it will be determined based on the fields you request.
 * If no entity_type is supplied and no fields are specified, 'Contact' will be assumed.
 * Optionally include the desired custom data to be fetched (or else all custom data for this entity will be returned)
 * Example: 'entity_id' => 123, 'return.custom_6' => 1, 'return.custom_33' => 1
 * If you do not know the ID, you may use group name : field name, for example 'return.foo_stuff:my_field' => 1
 *
 * @return array.
 *
 * @access public
 *
 **/

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Trouble Getting CustomValues
December 27, 2011, 05:16:06 pm
First of all you are misusing the API. civicrm_api3_custom_value_get is an internal function and should not be called directly.

Second of all, you probably have PHP error messages misconfigured and are getting the WSOD instead of a more descriptive PHP error. In this case the error is probably "call to undefined function" since you called a function you don't have access to (unless you manually included that file, and all the others that get automatically loaded by civicrm_initialize() and civicrm_api() ).

Try this:
Code: [Select]
civicrm_initialize(); // always call this before calling the api for the first time in a script
$params=array('entity_id' => 1, 'version' => 3, 'return.group_name:field_one' => 1, 'return.group_name:field_two' => 1);
$ret = civicrm_api('custom_value', 'get', $params); // this is the only public api function

I'm not sure if the return.group_name:field_name syntax is what we settled on, but at least that gets rid of the WSOD for you.
Try asking your question on the new CiviCRM help site.

kengle3

  • I’m new here
  • *
  • Posts: 16
  • Karma: 0
Re: Trouble Getting CustomValues
January 01, 2012, 04:52:19 pm
That fixed the issue for me, thanks. I don't know how I missed the wrapper function.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Trouble Getting CustomValues
January 06, 2012, 06:54:43 pm
If you figure out how you missed it you might be able to update whatever documentation led you astray....
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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Trouble Getting CustomValues

This forum was archived on 2017-11-26.