CustomValue.GetTree API Does Not Return Display Value for Money Select/Radio Custom field
Overview
The CustomValue.gettree API returns custom fields and its values for an entity. When the custom field is of data type Money and the field type is Select/Radio. The CustomValue.gettree does not return any value for the display field for the custom field even though there is data in the field.
Reproduction steps
Take for example a Case that has a custom group that has a Money select field with options Field Label: Two Dollars, Field Value : 2.
If the select option of Two Dollars is selected when creating the case and the API is invoked after creation:
$result = civicrm_api3('CustomValue', 'gettree', [
'entity_id' => 29,
'entity_type' => "Case",
]);
//Result
{
"is_error": 0,
"version": 3,
"count": 2,
"values": {
"Apha_Num": {
"id": "11",
"name": "Apha_Num",
"table_name": "civicrm_value_apha_num_11",
"title": "Apha Num",
"extends": "Case",
"is_public": "1",
"fields": {
"Money_Select": {
"value": {
"id": "9",
"data": "2.00",
"display": "" // THE DISPLAY FIELD IS EMPTY
},
"id": "40",
"name": "Money_Select",
"label": "Money Select",
"column_name": "money_select_40",
"data_type": "Money",
"html_type": "Select",
"option_group_id": "119",
"in_selector": "0"
}
}
}
}
}
Current behaviour
I did a bit of investigation about this. For Money fields that are select or radio, the values are stored in a DECIMAL column type in the database. These value stored in this field is formatted as decimal. So for the example given above. The value of 2.00 was stored in the column for the Case. While the option group created for the Select option values has a value of 2.
When the display for the Money field select type is being fetched here: https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/BAO/CustomField.php#L1120. The value set is an empty string because the options contain something similar to this
array (
2 => 'Two Dollars',
)
While the $value = 2.00
, So the value can not be found in the array and ''
is returned.
Expected behaviour
Ideally, I think the label for the option value (in this case Two Dollars) should be returned when the CustomValue.gettree API. Although the Money field is a bit different and not sure if it is the value (2.00) that should be returned in this case as the display field.