Checkbox (Lookup Table) question - choices are responses from previous repeat group question

Hi - I’m new to CommCare, having transitioned from a previous organization that used Surveybe. I’m creating a household registration form; there is a repeat group that ask questions that list each household member’s name, age, gender, etc.

I then want to ask a follow up checkbox (Lookup Table) question (which household members do x, y, z…), where the response options are the names household member names provided in the repeat group. This was fairly straightforward in Surveybe, but the closest response I can find in the help menus is one about “Multiple Choice Questions with Cases as Choices”. Effectively, I can’t sort out the query expression. Any guidance would be most appreciated!

Hi

I’ve personally done something similar.

what i’ve found to be most useful is to use the filter field with the function “selected”

the difference between what the documentation says about advanced lookup table questions (checkbox) is that the source in this case is not a lookup table, but the repeat group itself.

so, for the source, you would type something like data/repeat_group
then you can use some sort of shortcode for the family member’s name to use as a “key value” to store in the data field, and the name as a description to show up to the user. in our case, we ask for codes instead of names as to not collect any personally identifying questions as much as possible, then i just use the translate function to remove the spaces and any funny characters and use that value as the key value.

here’s an example of what i wrote in the data source section of a lookup question

/data/hh_mem_info[selected(#form/id_qs/members_with_natid, mem_shortcode_db)]

/data/hh_mem_info -> this is the actual repeat group, and also the source of all the household members.

[selected(#form/id_qs/members_with_natid, mem_shortcode_db)] -> is how i’m specifying the filter. #form/is_qs/members_with_natid is another multi-select checkbox question with household members as answers but is filtered for something else (14+years old)
mem_shortcode_db is that calculated property in the repeat group that removes those special characters and spaces from the member’s shortcode entered by the users. it is also what fills the members_with_natid question as space separated values.

here’s how the question is set up

image

and here’s how the repeat looks on the inside (it’s not the prettiest)
image

I hope this information helps you get what you want to get out of your application

Good luck!

Mazz

also, note how i’m using “/data/” instead of “#form

i had to dig somewhere deep in old forum discussion to find this piece of information out. it’ll drive you mad sometimes because if you use the features that automatically allows you to drag and drop fields, it’ll change it back to “#form” and throw the application an error.

make sure that the data source (lookup table) is using the “/data/” tag instead of the “#form” tag for those lookup questions with repeat group as answers.

Hi Mazz,

Thanks so much for sending the detailed response. I’m a bit confused by about what the calculation in the mem_shortcode_db hidden value should look like. I think I understand you to be saying it should give each member effectively a unique
sub-ID within each household, in order to store the data – but please correct me if not. However, I’m unsure how to do that.

Also, do I understand correctly that “members_with_natid” is the actual question in which this ‘lookup table data’ is located?

Thank you!

Stacy

Hi Stacy

suppose that your user enters something like “John smith” as a shortcode. or, A 001. if you tried to pull that repeat group into a lookup question, it’ll cause an error when it tries to use those values as the key value. the reason for that in this case is the space characters in the shortcode.

so, i decided to pull that shortcode into a hidden value and use this function to “translate” the spaces into underscore “_” characters. you can also use this function “replace” for a more straight forward approach.

if you put in a validation rule in the mem_shortcode text input, you can avoid having to do that. for that, i recommend using this function “regex” to create an expression that avoids any of the special characters you need to avoid.

as to your second question, yes. members_with_natid is a lookup question that’s a checkbox answer which is used to indicate which household members possess national id’s. the response will be stored as mem_shortcode_db values from the repeat group.

Hope this helps!

Mazz

Hi Mazz,

Thanks again for your help with this. I got the translate function sorted, so that I create a properly formatted value.

However, I think we are perhaps talking about different, but related tasks. You note that #form/is_qs/members_with_natid is another multi-select checkbox question with household members as answers. For that question, what is the source of the responses? Is it a lookup table that you brought into the project, or is were those responses created in a repeated group?

In my case, this is the baseline form, so I don’t know a) How many household members there are and b) What their names are. Therefore, I cannot create a lookup table with this information, but I’m hoping to “point” to that information in the responses from the repeated group. Thus, I think it might be slightly different from your example?

Thanks again!

Hi

if you repeat group is called “household_members_repeat”
and inside this repeat, you can type a shortcode for household members, let’s call is mem_shortcode
and you can also type in a name for the household member, let’s call that mem_name.

you then somewhere else in the form, have a lookup question.

for the data source, if you can only see an arrow to select from an existing set of already uploaded lookup tables, you need to your application settings->add-ons-> and then make sure that this option is checked

this will allow you to specify your own data sources for the lookup questions. instead of just a drop down list of lookup tables, you will also get an option that allows you to type your data source yourself like you can see here

if you click on the three dots, you will be able to type something. in there, you want to type /data/household_members_repeat
for the value field, you type mem_shortcode, and for the display text field, you type mem_name.

that should do the trick. you should then see household member names as options in your multi-select question

Hi Mazz,

Thanks again for your response. I did get this sorted with some internal help – the lookup table text was simply “#form /HH_Members” (which is the repeated group) and the value field and Display Text Field were both set to “Member_Name”
which is the question in the repeated group. It worked without the creation of any hidden values.

Again, greatly appreciate your time!

Stacy