Saving location name from multiple choice lookup table as a case property

commcare

I have set up an organization structure and am using a multiple choice lookup table within a form to reference the organization structure. Mobile users are asked to select the location in which they are working on a given day. Mobile users are assigned to all locations within the organization structure because they move between locations for their work.

I am saving the output of the multiple choice lookup table question as a case property, which by default generates the location ID. Instead of the location ID, I would like to display the location name that corresponds to the location ID that was generated in the multiple choice lookup table question.

I found instructions for displaying the user's location name in this article, but did not find the same for referencing the name of a selected location from a multiple choice question. Is there a syntax I could use to reference names from locations selected in a form?

Best Answer

Assuming your question is named /data/location_id_result, you can reference the name of the location selected with the expression

instance('locations')/locations/location[@id = /data/location_id_result]/name

and load that into a hidden value which you then save to the case.