diff --git a/api/v3/CustomValue.php b/api/v3/CustomValue.php index e5371f8feaf6..e98a1b5ba102 100644 --- a/api/v3/CustomValue.php +++ b/api/v3/CustomValue.php @@ -146,7 +146,7 @@ function civicrm_api3_custom_value_get($params) { foreach ($params as $id => $param) { if ($param && substr($id, 0, 6) == 'return') { $id = substr($id, 7); - list($c, $i) = CRM_Utils_System::explode('_', $id, 2); + list($c, $i) = CRM_Utils_System::explode('_', $param, 2); if ($c == 'custom' && is_numeric($i)) { $names['custom_' . $i] = 'custom_' . $i; $id = $i; diff --git a/tests/phpunit/api/v3/CustomValueTest.php b/tests/phpunit/api/v3/CustomValueTest.php index 791eea0344ce..02c1c29037b5 100644 --- a/tests/phpunit/api/v3/CustomValueTest.php +++ b/tests/phpunit/api/v3/CustomValueTest.php @@ -230,6 +230,22 @@ public function _testCustomValue($customField, $sqlOps, $type) { $params = array('entity_id' => $contactId, 'custom_' . $customId => $selectedValue); $this->callAPISuccess('CustomValue', 'create', $params); + $customValue = $this->callAPISuccess('CustomValue', 'get', [ + 'sequential' => 1, + 'return' => "custom_{$customId}", + 'entity_id' => $contactId, + ]); + if (is_array($selectedValue)) { + $expected = array_values($selectedValue); + $this->checkArrayEquals($expected, $customValue['values'][0]['latest']); + } + elseif ($type == 'date') { + $this->assertEquals($selectedValue, date('Ymd', strtotime(str_replace('.', '/', $customValue['values'][0]['latest'])))); + } + else { + $this->assertEquals($selectedValue, $customValue['values'][0]['latest']); + } + foreach ($sqlOps as $op) { $qillOp = CRM_Utils_Array::value($op, CRM_Core_SelectValues::getSearchBuilderOperators(), $op); switch ($op) {