Display the owner of a case in the case list

commcare

Although there is already a question regarding how to display a location name in a case list (Displaying location name from organizations lookup table in case list/case detalis), I have a lightly differently nuanced question regarding a similar output.

In an app with a supervisor >> CHW location hierarchy where only the CHW locations can own cases (supervisors can view cases but not own them), in a form that updates a case, if certain questions are answered a specific way, an alert is created and I want to create child cases for a supervisor module. In the case list of that module for the child cases being created (the "alert" case types), I want to display the location name that owns the case.

In the form creating the child cases, I save the owner_id of the owner of the parent case as a property for the child case. How do I reference that in the case list for the child case "alert" module? And is it going to be the "name" of the location or the alphanumeric location_id? Ideally I would like to reference the name of the location because they are saved as the name of the CHW whose mobile user is assigned to that location.

Best Answer

In your caselist use a calculate format to refer to:

instance('locations')/locations/location[@id = current()/@owner_id]/name

If you're using the older hierarchical location structures you'll need to customize it, something like:

instance('locations')/toplocations/toplocation/secondlevels/secondlevel[@id = current()/@owner_id]/name