Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

So what you're looking to do is create a multiselect that lists cases to be selected? Unfortunately this is not supported in CommCareHQ's Application Builder. It can be done through a custom method described below, but is not recommended.

 

Warning
titleThe process described below is not actively supported by CommCare
The instructions below are for advanced users only; Dimagi may not be able to help if you attempt to make changes to xml by hand and make a mistake.

 

Warning
titleThe process described below is not actively supported by CommCare
Full access to this feature is only available for projects on a Standard software plan or higher. For more information, see https://www.commcarehq.org/pricing/

This is useful if, for example, you have a form where you want to check off which of your cases are attending.

Modifying the XForm

If you are comfortable hacking around in the XForm, you can set up what you want by setting up an "itemset" which is based on the case database.
If you are not already using a form which required selecting a case, you will also need to add this xml right above where the app places all of the <bind> tags
<instance id="casedb" src="jr://instance/casedb"/>
Essentially: You'd create a select question, edit the XML, find the <select> block which represents your placeholder question and replace its <item> tags with the following (Only the bold parts of the XML below are changes. Everything else is what was there before). You'll need to include your case's "type" in the xml where noted
<select ref="/data/yourquestion">
   <label ref="jr:itext('yourquestion-label')" />

...

Multiexcerpt include macro
macro_uuid785c6088-0e28-4857-9b71-fdd34d840424
nameSoftware Plan - Standard
templateDataeJyLjgUAARUAuQ==
pageCommCare Help Site Design Guidance
addpanelfalse

This is now supported in the Application Builder using the 'Custom Single and Multiple Answer Questions' add on.

Step 1: Turn on the Feature Preview

Inside your form, you want to display existing cases in a checklist or single select question.  To do this, you need to turn enable an Add On called "Custom Single and Multiple Answer Questions".  This allows you to display custom choice lists in forms (i.e. a list of case sharing groups) instead of just items from a Lookup Table.

  1. Go to your Application Settings , then Select the Add-Ons tab.

  2. Choose the button with three lines on the right-hand side that is next to the save button and select 'Calculatons'

  3. Turn on the "Custom Single and Multiple Answer Questions" Add-Ons to enable the necessary feature:

Step 2: Configure Your Form

  1. In your form, add a new Checkbox Lookup Table question

  2. Choose the Lookup Table Data item below the added question to configure the data that will be displayed in the question.  Choose the (...) button and enter the following:

    1. Set the query expression to instance('casedb')/casedb/case[@case_type='your_type']

...

      <label ref="case_name"/>
      <value ref="@case_id" />
   </itemset>
</select>
The options will include all the cases on the tablet of type 'your_type' (including closed cases). 
If you want to list only open cases, you need to append a [@status='open'] clause as shown below:
<select ref="/data/yourquestion">
   <label ref="jr:itext('yourquestion-label')" />
   <itemset nodeset="instance('casedb')/casedb/case[@case_type='your_type'][@status='open']">
      <label ref="case_name"/>
      <value ref="@case_id" />
   </itemset>
</select>

Variations

...

    1.  (Replacing your_type with the case type you want to display)

    2. Set instance ID to casedb

    3. Set the Instance URI to jr://instance/casedb 

    4. Hit the Save button

    5. Set the value to @case_id 

    6. Set the label to case_name 

Variations

  • If you would like to restrict the cases shown to be only child cases of the chosen case which you are updating you can

...

  • add the following

...

  • to the end of the query: [index/parent = instance('commcaresession')/session/data/case_id]

 

For Dimagi people reference:

You can look at this app for reference: https://www.commcarehq.org/a/tdhtesting/apps/view/39d3a2c79d16e59d035a4093fa0cf3cd/modules-1/forms-2/source/

...

  • If you would like to restrict the cases shown to be only open cases you can add the following to the end of the query: [@status='open']