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 (Moderator: Donald Lobo) »
  • Custom Value API fails to insert multiple values when passed an array
Pages: [1]

Author Topic: Custom Value API fails to insert multiple values when passed an array  (Read 778 times)

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Custom Value API fails to insert multiple values when passed an array
October 04, 2012, 09:43:01 am
The comments for the CustomValue create API function (api/v3/CustomValue.php) state that you can use the function to insert multiple values for a field that allows multiple records by passing an array instead of a simple value:
Code: [Select]
// custom_24 is checkbox or multiselect, so pass items as an array
 * 'custom_24' => array('bar', 'baz'),
I've tried this and it doesn't seem to work. The CustomValue create function recognises the value as an array and implodes it into a string, which is then inserted into the custom table as a single value. What should happen is that each value in the array should be inserted into the custom table as a separate record.

I don't think I can recreate this on the demo server because I don't know how to make an API call to the demo server that passes an array as a parameter, but I've tried it on my 4.2.2 installation.

This looks like a bug, or at the very least a feature that hasn't been implemented yet. Is it?

britebyte

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 2
  • CiviCRM version: Several 3.4+, 4.1+
  • CMS version: Drupal 6, Drupal7
  • MySQL version: Several 5.1+
  • PHP version: Several 5.2+
Re: Custom Value API fails to insert multiple values when passed an array
October 24, 2012, 11:06:22 am
I'm pretty sure the API function you mention is working as designed because that format is for importing multiple values into a single field like a checkbox or multiselect field that hold a list of options.

I've never tried importing into a custom group that takes multiple values per contact but I will need to do that soon so I took a look.
I found this comment in CustomValueTable.php that might be what we need:
Code: [Select]
// custom_X => value or custom_X_VALUEID => value (for multiple values), VALUEID == -1, -2 etc for new insertions
If it works please let me know!

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Re: Custom Value API fails to insert multiple values when passed an array
November 27, 2012, 11:20:27 am
I'm looking to do the same thing. Did either of you have any luck with this?

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Custom Value API fails to insert multiple values when passed an array

This forum was archived on 2017-11-26.