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) »
  • Contact API and custom fields
Pages: [1]

Author Topic: Contact API and custom fields  (Read 1171 times)

chirayu

  • Guest
Contact API and custom fields
September 01, 2010, 07:27:10 am
Hi

I am trying to add data to a custom field for a contact.

The field type is integer text. Here is what I want to achieve:
> If updating a contact add the custom data as a new value (not to erase the earlier values). So the civicrm_contact_update function should not erase the earlier values and add this new value as a new record.

Can anyone be of any help?

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: Contact API and custom fields
September 01, 2010, 07:47:38 am

i dont think the contact add/update api calls know about multiple record custom groups

if this is an important feature, please consider investigating the code and adding support for this

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

chirayu

  • Guest
Re: Contact API and custom fields
September 01, 2010, 07:57:30 am

Leave the multi-value functionality, I simply want to add data to custom fields of a contact. I cannot do that with civicrm_contact_update. Here is my code:

Code: [Select]
$params = array( 'custom_15' => 100,
                        'contact_id'  => 102,
                        'contact_type' => 'Individual');

$contact = civicrm_contact_update($params);

I have run this, there is no error ('is_error' value in $contact is 0). However, the value 100 for the custom field is not showing in CiviCRM. Why is this?? Any fix??

chirayu

  • Guest
Re: Contact API and custom fields
September 03, 2010, 03:19:48 am
Found the error:

In CiviCRM, I checked the option 'View Only' while creating the custom field for Contacts. I did this so that I could only change the field using my PHP code and to disable users of CiviCRM from manipulating the field. The help option next to the 'View Only' says "Is this field set by PHP code (via a custom hook). This field will not be updated by CiviCRM."

The help is misleading. When I unchecked the 'View Only' and ran my PHP code I found that I had successfully made changes to the field using my PHP code.

For the administrators, is this a bug within CiviCRM? If so, could we have a fix?

Thanks for your help lobo.

Chirayu

chirayu

  • Guest
Re: Contact API and custom fields
September 03, 2010, 03:42:00 am
I just added a second record to the custom field. Done!!

Here is the code:

Code: [Select]
$params = array(
                       'custom_15' => '108',
                       'contact_id' => '102',
                       'contact_type' => 'Individual');
$contact = civicrm_contact_update($params);


$params = array(
                       'custom_15' => '101',
                       'contact_id' => '102',
                       'contact_type' => 'Individual');
$contact = civicrm_contact_update($params);

The above code displays two records for the field custom_15 in CiviCRM with values 108 and 101.
Hope it helps!




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

This forum was archived on 2017-11-26.