DET Tips and Tricks

Export repeat groups

  • Set the "Data Source" to be the path of your repeat group, e.g., form.form.question_group.repeat_group[*]

  • Reference the questions directly i.e. instead of "form.question_goup.repeat_group.question1" you should use "question1"

  • Reference root properties of the form with: $

    • e.g. $.form.@name, $.id

  • Reference the id of the repeat group with: id

Data Source

Filter Name

Filter Value

Field

Source Field

Data Source

Filter Name

Filter Value

Field

Source Field

form.form.path.to.repeat[*]





form_id

$.id







form_name

$.form.@name







repeat_question1

repeat_question1







repeat_question2

repeat_question2

Export a case or form in JSON representation 

  • Set the "Data Source" to "form" or "case", depending on what is supposed to be extracted. 

  • Set the "Source Field" to "[*]"

Data Source

Filter Name

Filter Value

Field

Source Field

Data Source

Filter Name

Filter Value

Field

Source Field

form





form_id

id







json_doc

[*]

In this query file, we are not applying any filters. Considering that the "Data Source" is generic, this would include all forms or cases regardless of their type.

Export one row for each case that was altered by a form

  • Use "form.form..case" as the data source.

  • Reference case properties directly, e.g., @case_id

  • Reference root properties of the form with '$' e.g. $.domain, $.form.@name

Data Source

Filter Name

Filter Value

Field

Source Field

Data Source

Filter Name

Filter Value

Field

Source Field

form.form..case





case_id

@case_id







form_name

$.form.@name







user_id

$.metadata.userID







form_id

$.id

Determine if a case was created, update, or closed by a form

  • Use the technique above to export one row for each case in the form

  • Reference the 'create', 'update', and 'close' fields in the case and map them via the 'bool' mapping

This will produce a 'True' or 'False' value in the output.

Data Source

Filter Name

Filter Value

Field

Source Field

Map Via

Data Source

Filter Name

Filter Value

Field

Source Field

Map Via

form.form..case





form_id

$.id









case_id

@case_id









created

create

bool







updated

update

bool







closed

close

bool

Determine if a form was submitted from a mobile phone or via some other means (API, bulk upload, Cloudcare, etc.)

  • Reference the 'is_phone_submission' property of the form

Data Source

Filter Name

Filter Value

Field

Source Field

Data Source

Filter Name

Filter Value

Field

Source Field

form





form_id

id







form_name

form.@name







is_phone_submission

is_phone_submission

Convert output values based on a mapping

Available in version 0.12.5 and above.

You may want to convert an output value to something else by doing a 'lookup' in some instances. For example:

Convert this output

→ To this output

Convert this output

→ To this output









To do this, we need to add a 'Mappings' sheet to our configuration file, which contains the lookups for the fields we want to convert.

Here is our configuration sheet:

And here we've added a new sheet called "Mappings", which contains 3 columns:

  • Mapping Name - this must match the name of a "Field" in the main configuration sheet

  • Source - this is the value that you want to convert from

  • Destination - this is the value that you want to convert to

Here is the Mapping sheet from our example:

form_link currently isn't available to be exported as a source field. In order to get the form_link, you can write the following expression in the "Map Via" Column: template(https://www.commcarehq.org/a/{}/reports/form_data/{}/, $.domain, $.id) (see screenshot below)

Data Source

Filter Name

Filter Value

Field

Source Field

Map Via

Data Source

Filter Name

Filter Value

Field

Source Field

Map Via

form





form_id

id









form_link

form_link

template(https://www.commcarehq.org/a/{}/reports/form_data/{}/, $.domain, $.id)

Export the Parent Case's ID

When exporting cases, if you need the parent's case_id or case_type, use the following source field:

Data Source

Filter Name

Filter Value

Field

Source Field

Data Source

Filter Name

Filter Value

Field

Source Field

case





id

id







parent_id

indices.parent.case_id







parent_case_type

indices.parent.case_type

Export the Host Case's ID

When exporting cases, if you need the host's case_id or case_type, use the following source field:

Data Source

Filter Name

Filter Value

Field

Source Field

Data Source

Filter Name

Filter Value

Field

Source Field

case





id

id







host_id

indices.host.case_id







host_case_type

indices.host.case_type