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) »
  • API Create: Custom field data not saved
Pages: [1]

Author Topic: API Create: Custom field data not saved  (Read 684 times)

amberau

  • I’m new here
  • *
  • Posts: 11
  • Karma: 0
  • CiviCRM version: 4.5.3
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.5
API Create: Custom field data not saved
January 01, 2015, 07:02:34 am
Hope someone can help with a puzzling problem. I can't save custom fields using the API create methods - and it doesn't work in the API explorer either. Same issue with both 4.5.4 and 4.5.5

There's no error being generated, the base fields save just fine, but the custom field data isn't created.

I've tried in my own extensions, API Explorer and in the API csvimporter extension - same result everywhere.

Works fine if I use CRM_Core_BAO_CustomValueTable::store

Here's an example that is not working, straight from the API explorer:

$result = civicrm_api3('Case', 'create', array(
  'sequential' => 1,
  'case_type_id' => 20,
  'subject' => "Testing",
  'custom_69' => 14,
  'contact_id' => 2,
));

Case is created perfectly. No value stored in the table for custom_69.

Am I missing something from the documentation? Is there something else I need to do for custom fields to work with the API?

Thanks in advance for your advice!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: API Create: Custom field data not saved
January 01, 2015, 07:44:29 am
Most but not all apis support custom data. Looks like case api is one of the ones that does not.
But you can get consistent results by using the custom_value api to store the custom field data after creating the case.
Try asking your question on the new CiviCRM help site.

amberau

  • I’m new here
  • *
  • Posts: 11
  • Karma: 0
  • CiviCRM version: 4.5.3
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.5
Re: API Create: Custom field data not saved
January 01, 2015, 08:49:25 am
Ah ok. Thanks for your response  ;D

Can you point me to any documentation that shows which entities support custom field creation through the API and which don't? I've got a lot of importing to do and it might be a bit horror if I have to use the custom value importer to do one custom field at a time.

EranSch

  • I post occasionally
  • **
  • Posts: 40
  • Karma: 3
    • Personal Blog
  • CiviCRM version: 4.5.X
  • CMS version: 4.X
  • MySQL version: 5.5.X
  • PHP version: 5.5.X
Re: API Create: Custom field data not saved
January 01, 2015, 08:53:18 am
The varied syntax is a little weird for the CustomValue API. Here's how I've been using it...

Code: [Select]
civicrm_api3('CustomValue', 'create', array(
'entity_id' => $entity_id,
"custom_{$custom_field_id}" => $value
));

In the code above, entity_id would be the id of whatever entity you're updating.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: API Create: Custom field data not saved
January 01, 2015, 09:48:50 am
If an api doesn't support custom data it's considered a bug and hopefully someone like you will help us fix it.
Almost all of them do. I think custom data was only added to CiviCase very recently and the api hasn't caught up.
Try asking your question on the new CiviCRM help site.

amberau

  • I’m new here
  • *
  • Posts: 11
  • Karma: 0
  • CiviCRM version: 4.5.3
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.5
Re: API Create: Custom field data not saved
January 01, 2015, 05:54:20 pm
Ok, well in that case a heads up that it doesn't work for campaigns either!

I thought about extending the API but that would mean a bit of rewrite on the importer module too, so I guess I'll have to add it to the API directly and hope the fix gets accepted and into a release in the near future.

Thanks for your assistance - and for the code, EranSch.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API Create: Custom field data not saved
January 01, 2015, 11:32:37 pm
I thought that custom data was working for most entities from 4.5 - albeit not campaign - ie.
https://issues.civicrm.org/jira/browse/CRM-15680
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) »
  • API Create: Custom field data not saved

This forum was archived on 2017-11-26.