I am using locations to assign cases to CHWs who belong to that location, using the Assigning Cases to One of Multiple Locations functionality. I would like to display the location name in the case detail page, however I can only show the location_id. I tried making a hidden field that is calculated as the owner name after the location has been selected, but I can’t figure out what needs to go in the calculate condition. Is there any other way to display the name and not the id?
You can read a bit on different patterns for referencing location data from this page on our wiki.
I think the calculation you’d want in your hidden value would be something like
instance(‘locations’)/locations/location[@id = #form/selected_location]/name
Where #form/selected_location is the lookup table question.
Is the issue that I’m trying to save location name as a case property in the registration form? When I use the above in the hidden value (in the same form that the location was selected), it remains blank. Can you only reassign ownership (to someone other than the creating user) after a case has been saved for the first time?
That sounds odd, can you confirm that you replaced the **#form/selected_location **reference in that expression with a link to your select question? That field should definitely be updated with the location name immediately after the location is selected.
Yes I did. The field is called owner_id, like in the example. Here’s another weird part of it - if I keep the assignment as my own location, the hidden field is populated with my location name, but if I select another location to assign the case to, the hidden field is blank. The actual owner/location of the case is properly updated, the hidden field just doesn’t recognize that.
My guess is that the issue is related to the ID reference itself in that case.
To confirm: The behavior you’re seeing is that your hidden value works when you reference the user’s location ID through the session, but not when you reference the ID of the chosen location from inside the form?
If you instead populate the hidden value calculation with only the ID reference portion (IE: what comes between “[@id=” and “]” above), is that populated correctly with the ID of the location?
Double checking: you’re performing the calculation of the name in the Hidden Value’s calculate section and not the default value section, right? In a default value calculation it would make sense for the value to have only been populated when calculated against the session, since those expressions are only triggered when the form is started and not when questions are changed.
Ok, I have an interesting update. I put two hidden fields at the end of the form one to display the id and one to display the name. The ID of the person/location selected from the lookup table is always populated correctly. If I select the admin level, the correct name shows correctly in the second hidden value field. If I select the level below admin (the supervisor level) the name shows correctly in the second hidden value field. If I select two levels below admin (the CHW level) the name is blank, but the ID is correct.
So in summary: yes to your question that the ID is populated correctly always. And yes the hidden value field to display name is in the calculate section, and works perfectly for the same level as the user, and one level below the user, but not for two levels below the user.
I tried looking at the levels available to each user, and how far their access extends into their descendants and there are no issues there.
Another update: It seems like there is some issue with being able to reference the location name of the newly assigned owner of a case, when that new owner is two levels below the current user (see the post above). In order to get around this I tried another way of referencing the location name of locations two levels below the current user.
Instead of using:
“instance(‘locations’)/locations/location[@id = #form/selected_location]/name”
which was only working for the current user, and locations in the hierarchy 1 level below the current user, I used:
“instance(‘groups’)/groups/group[@id = #form/selected_location]/name”
This second option at least didn’t give a blank response, but it did give the whole hierarchy as a response:
“Sierra Leone/Facility Users/Supervisor Name/CHW Name-Cases”
Is there a way to get just the “CHW Name” section of the response?
I can’t think of a way to use groups mechanism you mention here to get at the exact field, since the groups are a derivative data model.
You can investigate the raw body of the response to see what is inside of the query body for your project by navigating to the following in your web browser:
and logging in as
with their password (I recommend doing this in a Chrome incognito tab)
If you look at the section you’ll see the data that’s inside of the group model which you can query in the lookup.
This document will also show you the locations hierarchy for the user. It would be a good place to look to make sure that the name and id fields for the locations you are querying are being populated as expected.
I did the process you described above, but didn’t see anything that would lead me to believe this wouldn’t work. However, all of a sudden it is working without any issue. I am able to now see the CHW name in the formula even though they are two levels down in the hierarchy. All I can think that I did to change anything is that I re-copied the earlier suggestion “instance(‘locations’)/locations/location[@id = #form/chw_assignment/owner_id]/name” into the calculate box. Perhaps there was some kind of formatting issue there that I couldn’t see before, perhaps with the single quotes, which don’t seem to copy well from the forum directly to the app. Anyway, thanks for your help.
Am relieved to hear that it’s working, seemed like a very odd situation.
Please don’t hesitate to reach out if it acts up again.