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) »
  • Fetching custom field values
Pages: [1]

Author Topic: Fetching custom field values  (Read 1159 times)

xcf33

  • I post frequently
  • ***
  • Posts: 181
  • Karma: 7
  • CiviCRM version: 3.3.2
  • CMS version: Drupal 6.19/6.20
  • MySQL version: 5.x
  • PHP version: 5.2.6
Fetching custom field values
April 16, 2010, 12:10:16 pm
Hi, I am trying to do something very simple yet getting frustrated.

http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmpost

have the snippet for setting and getting custom fields and I followed them to a TEE.


Currently, I am using hook_civicrm_post with op = 'create' and objectName = 'Contribution' to capture some of the contribution information and insert them into another table. At the same time, I also wanted to get a custom field value that was from the contribution form as well.

The custom field id is 4.

So I did
Code: [Select]
$params = array('entityID' => $objectRef->contact_id, 'custom_4' => 1);

$values = CRM_Core_BAO_CustomValueTable::getValues($params);

It always come up and tell me

Array
(
    [is_error] => 1
    [error_message] => No values found for the specified entity ID and custom field(s).
)

So I looked into 'CRM/Core/BAO/CustomValueTable.php';

it was calling another function to get the custom field value:

getEntityValues

So I called
Code: [Select]
$values = CRM_Core_BAO_CustomValueTable::getEntityValues($objectRef->contact_id, null, array(4));

I also got an empty array in return.


I have tried to use the $objectRef->id instead of $objectRef->contact_id for the entityID, assuming that because the custom field group is made for contributions, however, it did not work either.


I have assumed that since I'm using the hook_civicrm_post

The contribution data as well as other form data should already be saved into the database and I have been able to get all the data from the Contribution object but not from the custom field.



Any help would be appreciated!



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: Fetching custom field values
April 16, 2010, 04:52:18 pm

you might want to add some debugging statements:

CRM_Core_Error::debug( $objectRef );

to see what the contents of objectRef are, that might give you a clue. Another option might also be to test those functions with id's that are known and valid

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

jsherk

  • I post occasionally
  • **
  • Posts: 82
  • Karma: 0
Re: Fetching custom field values
April 22, 2010, 09:37:28 pm
xcf33: Can you point me to code snippet you are talking about... I need to figure out how to add/update info in custom fields using API.

Thanks

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

This forum was archived on 2017-11-26.