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 (Moderator: Donald Lobo) »
  • Custom field/object API changes in v2.0
Pages: [1]

Author Topic: Custom field/object API changes in v2.0  (Read 2765 times)

xmatt

  • Guest
Custom field/object API changes in v2.0
March 24, 2008, 08:26:22 am
Sorry if this is documented somewhere, but I've looked very thoroughly at the API documentation and can't seem to find the answer, so here goes:

I'm working on upgrading my organization's CiviCRM install from 1.9 to 2.0. The upgrade process went fine, we but have some custom Drupal  (5.x) modules that use CiviCRM API functions. Several of these functions were removed from the API in version 2.0.

In particular, crm_get_custom_field and crm_get_option_values are gone. There doesn't seem to be any obvious successor (as in crm_get_contact becoming civicrm_contact_get). Is it still possible to access custom field data with the API?

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Custom field/object API changes in v2.0
March 24, 2008, 01:39:56 pm
I think you'll have to invoke methods directly for this now.

Note that all "options" for custom fields are now stored in civicrm_option_value rather than civicrm_custom_value. The option_group_id for the set of values is stored in civicrm_custom_field.option_group_id.
Protect your investment in CiviCRM by  becoming a Member!

xmatt

  • Guest
Re: Custom field/object API changes in v2.0
March 24, 2008, 02:03:04 pm
Bummer. Are there any plans to add this to the v2 API? It seems like a logical addition to the existing v2 functions to handle custom field groups and custom fields.

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: Custom field/object API changes in v2.0
April 08, 2008, 03:38:14 am
xmatt, check the functions in CRM_Core_OptionGroup - eg CRM_Core_OptionGroup::valuesById($oid) will give you an array of the available options for a custom field

Code: [Select]
require_once 'CRM/Core/OptionGroup.php';
$customFieldId = 33 ;
$optionValues = CRM_Core_OptionGroup::ValuesById($customFieldId);

if you work out more examples of how to implement functions which have gone since 1.x series, please add them to this thread so I can update the docs

http://forum.civicrm.org/index.php/topic,3008.0.html

cheers
@xurizaemon ● www.fuzion.co.nz

ijames

  • Guest
Re: Custom field/object API changes in v2.0
April 09, 2008, 01:14:00 am
I believe this thread is related and shows an easier way of modifying custom fields with civicrm_contact_add() but I'm not sure it's working perfectly yet. 

Also note that for checkbox fields and/or other multiple entry custom fields, another user pointed out that it would be done with array('value1','value2').

In other words, this should work:

$params = array(
  'contact_id'=>$contact_id,
  'custom1'=>'my new value',
  'custom2'=>array('itsacheckboxcustomvalue','itsgotmultiplefields','yesitdoes'),
);
civicrm_contact_add($params);


At least that's what I'm gleaning from it.  But it's not working for me.  Apparently there are code upgrades that must be put in place (Contact.php, and utils.php) but those didn't seem to make it work.

Here is the other thread: http://forum.civicrm.org/index.php/topic,2967.0.html

James

Manish Zope

  • I’m new here
  • *
  • Posts: 18
  • Karma: 4
Re: Custom field/object API changes in v2.0
April 09, 2008, 09:14:54 am
check this reply

barrylb

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
Re: Custom field/object API changes in v2.0
May 21, 2008, 03:28:49 am
Quote from: xurizaemon on April 08, 2008, 03:38:14 am
Code: [Select]
require_once 'CRM/Core/OptionGroup.php';
$customFieldId = 33 ;
$optionValues = CRM_Core_OptionGroup::ValuesById($customFieldId);

I tried using this function but the parameter taken by ValuesById is actually option_group_id, not the custom field id so it doesn't work as presented here.  I can see the option_group_id value in the database tables as described by Dave Greenberg above.. but does anyone know which function (API or otherwise...) to use to get the option group id?  It is not returned in CRM_Core_BAO_CustomField::getFields() either...

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Custom field/object API changes in v2.0

This forum was archived on 2017-11-26.