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) »
  • After upgrading to 4.4.4, some API calls stopped working (individual_prefix)
Pages: [1]

Author Topic: After upgrading to 4.4.4, some API calls stopped working (individual_prefix)  (Read 477 times)

carlitos

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
    • International Council for Traditional Music
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 6
  • MySQL version: 5
  • PHP version: 5
After upgrading to 4.4.4, some API calls stopped working (individual_prefix)
March 07, 2014, 02:06:12 pm
Hello all,

I upgraded yesterday from 4.1.5 to 4.4.4 (under Drupal 6). I realised that the field "individual_prefix" was renamed, at least from the API point of view, to 'prefix_id'. I'm fine with that, but my code is now broke, and I can't seem to be able to quickly fix it.

I can't get the prefix's value (e.g., "Mr", not an integer) via the API. The data is saved to the DB, but the API calls I'm using (either in code or via the API explorer) always return an empty prefix_id.

The code I used in 4.1.5 was (at CRM/Profile/Page/Dynamic.php):

Code: [Select]
$displayName = ($profileFields["individual_prefix"]["value"] ? $profileFields["individual_prefix"]["value"] . " " : "") . CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_id, 'addressee_display');

Replacing "individual_prefix" with "prefix_id" doesn't work as I'd hope, and $profileFields["prefix_id"]["value"] returns always empty (again, so it does via the API explorer). If I'd get an integer I'd lookup the value to another table (like I do with profile images, for example), but since prefix_id comes always empty, I'm at a loss.

Could anybody help me, please? I'm quite worried. I looked everywhere online, but I couldn't find any reference to the field rename. In my experience APIs shouldn't change so drastically, but as long as I learn the new syntax, I'm fine.

Thanks a lot,

Carlos

andrewhunt

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 13
    • AGH Strategies
  • CiviCRM version: all of 'em
  • CMS version: Drupal, Joomla, and WordPress
Re: After upgrading to 4.4.4, some API calls stopped working (individual_prefix)
March 07, 2014, 04:10:39 pm
individual_prefix is an option group

You'll need to do two things:

1. get the option_group_id of individual_prefix
Code: [Select]
try{
  $params = array(
    'sequential' => 1,
    'name' => 'individual_prefix',
  );
  $prefix_id = civicrm_api3('OptionGroup', 'get', $params);
}
catch (CiviCRM_API3_Exception $e) {
   $error = $e->getMessage();
}

2. then get the prefixes

Code: [Select]
try{
  $params = array(
    'sequential' => 1,
    'option_group_id' => $prefix_id[0]['id'],
  );
  $prefixes = civicrm_api3('OptionValue', 'get', $params);
}
catch (CiviCRM_API3_Exception $e) {
   $error = $e->getMessage();
}
You can find me at AGH Strategies.
Need help now?  Civi911 is your go-to for CiviCRM support.

carlitos

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
    • International Council for Traditional Music
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 6
  • MySQL version: 5
  • PHP version: 5
Re: After upgrading to 4.4.4, some API calls stopped working (individual_prefix)
March 07, 2014, 04:16:32 pm
Thanks a lot for the reply. I'll try and report back.

carlitos

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
    • International Council for Traditional Music
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 6
  • MySQL version: 5
  • PHP version: 5
Re: After upgrading to 4.4.4, some API calls stopped working (individual_prefix)
March 09, 2014, 03:29:17 pm
This indeed did help. It made me understand how the prefixes (as well as the rest of the option groups) were accessed by the API. Thanks a lot!


Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: After upgrading to 4.4.4, some API calls stopped working (individual_prefix)
March 16, 2014, 03:38:07 pm
I would expect (haven't tried) that civicrm_api3('contact', 'getoptions', array('field' => 'prefix_id') would retrieve them too

(I think it's field - it might be 'name')
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) »
  • After upgrading to 4.4.4, some API calls stopped working (individual_prefix)

This forum was archived on 2017-11-26.