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) »
  • Strange name for custom field in individual object (hook civrm_pre)
Pages: [1]

Author Topic: Strange name for custom field in individual object (hook civrm_pre)  (Read 622 times)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Strange name for custom field in individual object (hook civrm_pre)
May 07, 2013, 06:28:44 am
Hi guys and girls,

I am using the civicrm_pre hook to pick up an Individual. In the object I get all relevant data from the object, including the custom fields. However, for custom field with the id 3, I would expect the label custom_3. I get custom_3_26800 though. Why is that and what is the logic?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Strange name for custom field in individual object (hook civrm_pre)
May 07, 2013, 06:46:07 am
Okay, answer from Jaap across the room... that is the id of the record in the civicrm_value_xxx table. I sure hope I get this in the Custom API :-)
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Strange name for custom field in individual object (hook civrm_pre)
May 08, 2013, 05:34:57 am
Yes, those field names are confusing. But if you use the API the table row id should be transparent. If, for whatever reason, you can not use the API, then you have to filter out that id somehow.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Strange name for custom field in individual object (hook civrm_pre)
May 09, 2013, 08:31:19 am
The id only shows up in the API when the custom field is a repetitive group, not if it is not as far as I can see. The custom value is retrieved using the BAO:
Code: [Select]
  $result = CRM_Core_BAO_CustomValueTable::getValues($getParams);

and that result array does not include the id either if it is not a repetitive group. It needs to be fixed because the civicrm_pre hook will have the id as part of the custom field definition (custom_1_123). I am using that hook to check what the value of some fields is, and then use the API to compare those fields against the values currently in the database to establish if anything has changed and needs to be synchronized. And if the API does not throw up the id I have to go to the table directly.
I am just contemplating what the best fix would be though...probably adding a record_id to the values array element that the API returns.
« Last Edit: May 09, 2013, 08:46:59 am by Erik Hommel »
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Strange name for custom field in individual object (hook civrm_pre)
May 09, 2013, 08:55:53 am
Just checked that the BAO only returns the additional id for a repetitive custom group. The pattern is:
Code: [Select]
Array
(
    [is_error] => 0
    [entityID] => 6
    [custom_1] => 55447891
    [custom_2] =>
    [custom_3] => 3
    [custom_25] =>
    [custom_26] =>
    [custom_27] =>
    [custom_28] =>
    [custom_29] =>
    [custom_30] =>
    [custom_31] =>
    [custom_32] =>
    [custom_33] => 0.00
    [custom_56] =>
    [custom_48_67711] => upd
    [custom_49_67711] => address
    [custom_50_67711] => 136826
    [custom_51_67711] =>
    [custom_52_67711] => 2011-06-03 00:00:00
    [custom_48_67787] => ins
    [custom_49_67787] => phone
    [custom_50_67787] => 116788

So ideally the BAO function should always use this pattern for the custom values. Agree?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Strange name for custom field in individual object (hook civrm_pre)

This forum was archived on 2017-11-26.