Using dynamic data attachment to populate choice lists for select_one and select_multiple fields

@DanielJohnRead, thank you for getting back to us. If you are still interested in sponsoring this feature, please reach us through info@kobotoolbox.org. We could then share the quote and the tentative time to develop this feature.

This would solve the majority of the limitations to perform a complete longitudinal survey! Hoping to hear some good news on this front soon!!

1 Like

Welcome to the community, @tharindu! Please feel free to sponsor this feature to see it being integrated into the system.

any update about this ?

Dear all, we would also appreciate if this feature will get integrated soon.

Is there a way to sponsor the development of this feature commonly by all parties interested and willing to share the costs?

Dear All,

I had a conversation with a KoboToolBox representative several months back, and the issue is in how XLSForms are structured. Options for choice_lists are baked into the XLSForm that is uploaded to KoboToolBox/ODK. These XLSForms are independent of the data that is entered into the form, and the two do not communicate with each other. Because of this, implementing this feature likely requires a heavy restructuring of how XLSForms work with Kobo/ODK.

I did receive a price estimate for this change, but I’m not sure it is appropriate to list publicly, though @Kal_Lam, please correct me if I am wrong. Suffice to say, unless several people have grants that they’d like to pool, or if we get thousands of people to pool their own money, this is likely out of reach.

Dear DanielJohnRead,

I also asked for a quote, but still waiting. I think this is an important limitation to Kobo, that should get resolved. Because maintaining manualy always changing csv files is not efficient. I am not an technician, so I cant’t really judge on the difficulties. But since it is possible to retrieve information from another object it should – i think and hope – be possible to make them available also in form of a select_one or so list.

Hi everyone, I just wanted to share a workaround that I used to make this work, even without being able to directly populate choice lists using another Kobo form. I used this strategy to populate a list of products for a given company, pulling the list from a Kobo form called “product list.” Here are the steps that I took:

  1. In the parent form (product list), I had a field for the company and then fields for the name and label of each product. The label was the name of the product as entered by the respondent, and the XML name was calculated based on this label (removing capital letters and replacing spaces with underscores).
translate(${full_name1}, "ABCDEFGHIJKLMNOPQRSTUVWXYZ -", "abcdefghijklmnopqrstuvwxyz_")
  1. The dataset for the parent form therefore included the following variables: company, product1_name, product1_label, product2_name, product2_label, etc. There was one entry per company.

  2. In the child form, I pulled in those variables with dynamic linking and using company as the identifier. I.e., if Company A was selected, the form pulled in names and labels for product 1 through 5 for Company A.

instance('products')/root/data[company = current()/../company_name]/product1/name1
instance('products')/root/data[company = current()/../company_name]/product2/name2
instance('products')/root/data[company = current()/../company_name]/product1/label1
instance('products')/root/data[company = current()/../company_name]/product2/label2
  1. Using these new variables in the child form, I populated the choice list like this:

Screenshot 2023-11-13 at 12.58.55 PM

The main limitation to this approach is that you have to account for the maximum number of options that can be pulled into the form, as you need to manually import each option as a new variable. In my case, I knew there would be a maximum of 5 products, so I built the form to import 5 products, but I added a choice filter to hide options if they were empty (i.e., only show 4 if only 4 products were entered).

Hope this helps!

5 Likes

@ salomegarnier,this method is a nice workaround.

1 Like

Thanks for sharing,
I would recommend to also test the export of the data (XML values and labels, SPSS labels), as the $-reference might not show the replacement.

1 Like

Can you please share a sample xls file for this?

Thank you.

As of now there are two limitation of this dynamic data attachment

  1. There is a delay of about five minutes between a data is submitted and it becomes available for other project (or itself).
  2. You can not display the fetched data as a list and allow user to choose (as the standard concept of foreign key used in DBMSs) instead you will have to enter key in a text box and relevant record(s) will be searched using that key.

Hint; Offering (simple) choice lists from external files is possible, see Form Datasets - ODK Docs.

That is correct in case of select from file, not in case of dynamic attachment (getting data from other existing projects or the current project itself).

1 Like

Yes, you can utilize the dynamic data attachment feature to populate choice lists for select-one and select-multiple questions. By referencing answers submitted in a text field from another form, you can achieve this. While the current documentation illustrates how to dynamically select answers based on unique identifiers, adapting it for tag fields should be feasible. It’s worth experimenting with, and any insights or experiences shared would be greatly appreciated.