Referencing Organizations with filtered multiple choice questions

I’ve set up my project space with Organizations and it has levels 1-4. I would like to set up a series of multiple questions for the users (assigned to levels 2 and 3) to select the facility (level 4) to which the data applies. I’m trying to follow the instructions shown here: https://confluence.dimagi.com/pages/viewpage.action?pageId=38276915 under ‘Making select questions with locations as choices’. I’m getting the error message “Make sure the ‘locations’ lookup table is available, and that its contents are accessible to the current user.” Do I also need to create lookup tables? I thought Organizations eliminated the need for that step? Thank you!

Hi Jenn,

Could you try to Sync with Server on the device that you are getting that error? That error usually means the location hierarchy hasn’t been sent to the phone yet.

-Nick

Thanks Nick. It seems a bad internet connection wasn’t syncing everything without indicating an issue.

Now the organizational structure is loading, but I’m stuck on the filtering. I have a multiple choice with question_id ‘province’ to select the level 1 location, and a multiple choice with question_id ‘district’ to select the level 2 location.

For the second question, when I set the filter to ’ @level-1_id = #form/section_0/province’, it shows everything in the entire hierarchy, not just level-2 locations. I went back into the form builder and it looks like the query expression is being changed when I add the filter expression. So in this second multiple choice question I can have either (a) only level 2 locations but without any filter, or (b) every location in the hierarchy (levels 2-4) that falls under the location chosen for level 1. What I need is a combination of these two things. What am I missing?

Hi Jenn,

You should be able to filter by both of those writing your filter expression as:

@type = ‘level-2’ and @level-1_id = #form/section_0/province

There’s also a button to the right of the “filter” box that lets you add the filters more easily

I’ve got my filters working, thanks all! Now a question about the data itself… because the filters reference @id, that is what’s being recorded in the form data. How can I have it record the name of the location rather than (or in addition to) the id of the location?

xHi Jenn,

If your lookup tables are large enough to cause performance issues with this filtering, you can update the filters to use a different syntax but you’ll need to enable Custom Single and Multi-Select Answers in your form.

After doing so you can define a custom lookup table query referencing the locations structure. The key change will be shifting from defining your filter all at once (X and Y) to defining multiple filters in a row [X = ‘x’][Y=‘y’]

In your case I believe that query and filter would be something like

instance(‘locations’)/locations/location[@type = ‘level-2’][@level-1_id = #form/section_0/province]

I believe you will need to update the #form reference to instead use a full path to that question in the “/data/” syntax, but I could be wrong about that.

The second confluence page also illustrates referencing a location’s name from the locations structure after the ID has been selected, to answer your latest question.

-Clayton