Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-13544

API: checkbox/multiselect custom fields expect a strange structure

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Duplicate
    • Affects Version/s: 4.3.7
    • Fix Version/s: 4.5
    • Component/s: None
    • Labels:
      None
    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Needs Funding

      Description

      Related: http://issues.civicrm.org/jira/browse/CRM-8131
      http://forum.civicrm.org/index.php?topic=20564.0

      I am trying to write checkbox values to the v3 API (contact object).
      According to the comments at the top of CustomValue.php:

       // custom_24 is checkbox or multiselect, so pass items as an array
       * 'custom_24' => array('bar', 'baz'),
      

      I tried writing using this code:
      $params['custom_37'] = array("Sjogrens Syndrome","HIV");
      however regardless of what values I put in the array, the values were being set to 0 and 1 in the database.

      I confirmed that it is using array keys instead of values by trying with:
      $params['custom_37'] = array(3=>4,5=>6);
      This resulted in 3 and 5 being set in the database.

      I tried debugging inside CustomValue.php (function civicrm_api3_custom_value_create) but that function does not seem to get called at all.
      For a second I thought that I should be looking somewhere else (i.e. this creates an actual value option for a custom field rather than saving a value), but the nomenclature suggests that "creating" a custom value means creating/updating an object that has a custom field (for example, in api/v3/examples/Contact/CustomFieldCreate.php)

      For now I am just using the array keys, but eventually we should correct either the documentation or the code.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jackrabbithanna Mark Hanna
                Reporter:
                rares Rares P
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: