Manager/Creator Information not being returned for case related contacts when fetching Case Details
Overview
When Fetching a case details e.g by calling the Case.get API, related contacts are returned with extra information returned for creators and managers (see: https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/BAO/Case.php#L1198)
e.g
{
"contacts": [
{
"contact_id": "2",
"display_name": "Tetss ssss",
"sort_name": "ssss, Tetss",
"relationship_type_id": "11",
"role": "Case Coordinator is",
"email": "admin@example.com",
"phone": "",
"manager": "1" //Manager details added here. Part of extra information for case related contacts
}
]
}
Issue
When saving sase soles for a case type, It is the reverse relationship type that gets saved for the case type. e.g if the case role label_b_a
is displayed as the option label relationship type when
adding a case role to a case type, when this gets saved, it is actually the name_a_b
that get saved in the database for that relationship type
Please see the code that generates the relationship type options used for this screen here: https://github.com/civicrm/civicrm-core/blob/master/ang/crmCaseType.js#L335-L338
Not sure why the order is reversed as this seems intentional. However this has some implications:
When calling the Case.get API, it returns related contacts along with the API results. It should also add the details or more info about the role (creator, manager) for applicable contacts also, so that for contacts that has a manager role, the manager => 1
is returned along with the contact information, this helps identify the manager quickly. https://github.com/civicrm/civicrm-core/blob/master/api/v3/Case.php#L626
However this line here (https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/BAO/Case.php#L1199) returns a NULL even when there is a valid case
manager for the case and as such the extra information is not added. The reason is that the $CaseRoles
array here(https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/BAO/Case.php#L1138) fetches the case roles stored in the case type definition which is fine but the results of the query returns the role name that does not match what is stored for the case role.
Reproduction steps
For example for the default relationship type that ships with civicrm
Name AB = Case Coordinator is
Label AB = Case Coordinator is
Name BA = Case Coordinator
Label BA = Case Coordinator
If I add this relationship type as a case role and as manager i.e as Case Coordinator is
(Name AB) for a case type, it is the (Case Coordinator) that gets saved in the definition column in case_type table. If I then assign a contact as the (Case Coordinator is) for a contact (client) then create a new case with this contact as the case client.
Current behaviour
When I try to get the Case Details for this case, when this query is ran https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/BAO/Case.php#L1142-L1176, it returns the Case Coordinator is
as the role name for the related contact which is fine but this line
https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/BAO/Case.php#L1199 returns NULL because what is saved in the case definition is the reverse relationship name i.e (Case Coordinator
) hence, the extra details is not added for the contact.
{
"contacts": [
{
"contact_id": "2",
"display_name": "Tetss ssss",
"sort_name": "ssss, Tetss",
"relationship_type_id": "11",
"role": "Case Coordinator is",
"email": "admin@example.com",
"phone": "",
}
]
}
In previous versions of Civicrm e.g 5.15
, the relationship type options were not swapped and this functionality worked fine, see https://github.com/civicrm/civicrm-core/blob/5.15/ang/crmCaseType.js#L266-L295
Expected behaviour
When I try to get the Case Details for this case, the extra details such as manager => 1
should be added for the Contact who is the Case Coordinator for the Client.
{
"contacts": [
{
"contact_id": "2",
"display_name": "Tetss ssss",
"sort_name": "ssss, Tetss",
"relationship_type_id": "11",
"role": "Case Coordinator is",
"email": "admin@example.com",
"phone": "",
"manager": "1" //Manager details added here
}
]
}