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) »
  • Updating custom data for Individuals appears to not be working
Pages: [1]

Author Topic: Updating custom data for Individuals appears to not be working  (Read 1884 times)

hlevinson

  • I post occasionally
  • **
  • Posts: 53
  • Karma: 3
Updating custom data for Individuals appears to not be working
February 02, 2010, 04:00:30 pm
This is in 3.1.1, and if it matters this was an update from 3.1 beta 2 on Drupal 6.15.

I created a custom data field group and field for Individuals using the CiviCRM UI.

I'm trying to run the following code. It runs without throwing any errors, but it never adds data.

Code: [Select]
civicrm_initialize( );
require_once("api/v2/Contact.php");
require_once("CRM/Contact/BAO/ContactType.php");
require_once("CRM/Core/BAO/CustomField.php");

$custom_field_name = 'custom_6';

$params = array(
  'contact_type'  => 'Individual',
  'first_name'    => 'Test',
  'last_name'     => 'Test645pm',
  "$custom_field_name"      => 'TEST645PM Test',
);
$contact = &civicrm_contact_add( $params );

print_r( $contact );


I also tried the update case the usual way by providing the contact type and ID, that also fails without throwing any errors.

I verified that I have the correct custom field ID (by checking the db and the URL on the custom field edit page). Also, my code for updating custom data for an Organization (that happens to be a subtype) still works OK.

On a related note, the test page here

http://svn.civicrm.org/civicrm/trunk/tests/phpunit/api/v2/CustomValueContactTypeTest.php

doesn't appear to test adding/updating custom data for an Individual contact record.

Harry


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: Updating custom data for Individuals appears to not be working
February 02, 2010, 08:12:50 pm

u need to use:

'custom_FIELDID' =>'FIELD VALUE',

where FIELDID is the db id of that custom field

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

hlevinson

  • I post occasionally
  • **
  • Posts: 53
  • Karma: 3
Re: Updating custom data for Individuals appears to not be working
February 03, 2010, 07:22:36 am
Yes, that's what I was doing   ;)

The problem is this bug regarding the is_view field setting:

http://issues.civicrm.org/jira/browse/CRM-5686


I confirmed this was the case by:

1. Changing my custom field to be NOT "view only" (although I actually wish it to be view only)
2. Truncated civicrm_cache table in MySQL
3. Re-ran my code above
4. Checked custom data table in MySQL -- my change is there
5. Tested the Update case of my code, and verified that data was in the database too

Harry



kaldari

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
Re: Updating custom data for Individuals appears to not be working
August 03, 2010, 01:54:07 pm
It's also important to make sure your script is running as a user with adequate permissions. There is a separate permission specifically for assessing custom data.

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Updating custom data for Individuals appears to not be working
September 07, 2012, 12:28:01 pm
Hi

I ran right in to this one - wasted 6 hours before I found this forum post :/
I couldn't figure out why on earth I couldn't set the custom value with the API. Finally I found this forum post, I unticked the "view only" for the custom field - tadaaa, no problem anymore. Though I would much prefer it to be view only, I'll move on now.

Since this bug is still here and the Issue linked to above is closed, should I (or someone else) reopen it, or make a new issue?
Same question for replying to old posts like this - is it better to start a new topic?

Best regards
/Anders:)
PS: I'm on Drupal 7, CiviCRM 4.1.3

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Updating custom data for Individuals appears to not be working
September 07, 2012, 03:11:53 pm
Quote from: andersiversen on September 07, 2012, 12:28:01 pm
Since this bug is still here and the Issue linked to above is closed, should I (or someone else) reopen it, or make a new issue?

PS: I'm on Drupal 7, CiviCRM 4.1.3

Are you having the problem with the api v2? It has been deprecated since several versions. I would urge you to switch to api v3 (that has an api for custom data).

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Updating custom data for Individuals appears to not be working
September 07, 2012, 03:50:15 pm
Nope. I'm using v3 - like this:

Code: [Select]
$params = array (
                'version'        => 3,
                'id'                => $contactID,
                'custom_49' => $IDnummer, 
                'custom_8'   => $year,
    'custom_9'   => $class,
    'custom_28' => 0,
    'custom_32' => 0,
    'custom_36' => 0,
              );
$results = civicrm_api( 'Contact','create', $params );

and it doesn't matter if I use $results = civicrm_api( 'Contact','update', $params ); or
$results = civicrm_api( 'CustomValue','create', $params ); or
$results = civicrm_api( 'CustomValue','update', $params );

Where for the latter two I've switched 'id' with 'entity_id' - though looking at it now.. I cannot use 'custom_32' etc. with the CustomValue can I ? If I want to update a bunch of custom fields with CustomValue update, how should the $params array look? This is probably the solution for me :)

Issue is still there with the contact create/update though...

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Updating custom data for Individuals appears to not be working

This forum was archived on 2017-11-26.