Hey everyone,
I wanted to share some insights on using the %e DREL expression to extract answers from repeatable sections in TrueContext forms.
Background
The %a[question_id] DREL expression extracts answers for a specific question. However, when used in a repeatable section, it retrieves answers from every row in that section. Consider a repeatable section, Grocery List that has 3 rows of answers. The DREL expression %a[Item Name] would return the answer from every row, Bread Milk Eggs.
Repeatable Section (ID: Grocery List)
|
Question (ID: Item Name)
|
Question (ID: Item Quantity)
|
Question (ID: Purchased?)
|
Bread
|
2
|
true
|
Milk
|
1
|
false
|
Eggs
|
3
|
true
|
Solution: The %e Expression
The %e[repeatable_section_id] expression retrieves answers from a specified repeatable section.
Filtering by Row
To extract answers from a specific row, use:
- %e[repeatable_section_id][n] – Extracts all answers from row n (0-based index).
- %e[repeatable_section_id][n][inner_drel] – Extracts answers from row n using an inner DREL expression.
Based on the repeatable Grocery List data found above, these expressions give the following results:
DREL Expression
|
Result
|
%e[Grocery List]
|
Bread 2 true Milk 1 false Eggs 3 true
|
%e[Grocery List][0]
|
Bread 2 true
|
%e[Grocery List][1][Buy: %a[Item Name] x %a[Item Quantity]]
|
Buy: Milk x 1
|
Format Answers with a Delimiter
When extracting answers, use a delimiter to separate them.
Syntax
%e[repeatable_section_id][inner_drel][delimiter]
- inner_drel: Specifies which answers to extract.
- delimiter: Separates the answers.
Example
DREL Expression
|
Result
|
%e[Grocery List][%a[Item Name]][, ]
|
Bread, Milk, Eggs
|
%e[Grocery List][%a[Item Quantity]][ + ]
|
2 + 1 + 3
|
Nested Repeatable Answers
When a repeatable section contains another repeatable section, use %e within an inner_drel expression.
- %e[repeatable_section_id][0..n][%e[nested_repeatable_section_id][0..n][inner_drel]]]
Consider data for a Store List section that contains a nested Grocery List as follows:
Repeatable Section (ID: Store List)
|
Question (ID: Store Name)
|
Repeatable Section (ID: Grocery List)
|
Question (ID: Item Name)
|
Question (ID: Item Quantity)
|
Question (ID: Purchased?)
|
Loblaws
|
Bread
|
2
|
true
|
Milk
|
1
|
false |
Eggs
|
3
|
true
|
Walmart
|
Batteries
|
5
|
false
|
Pillows
|
2
|
false
|
These expressions give the following results:
DREL Expression
|
Result
|
%e[Store List][1][%e[Grocery List]]
|
Batteries 5 false Pillows 2 false
|
%e[Store List][1][%e[Grocery List][0]]
|
Batteries 5 false
|
%e[Store List][0][Buy: %e[Grocery List][2][%a[Item Name]] from %a[Store Name]]
|
Buy: Eggs from Loblaws
|
%e[Store List][0][%a[Store Name] Items: %e[Grocery List][%a[Item Name]][, ]]
|
Loblaws Items: Bread, Milk, Eggs
|
For more detailed information, refer to the DREL Complete Reference List in our documentation.
Hope this helps!
#TechTalkImplementation
------------------------------
Rob Dods
Analytics Implementation Specialist
TrueContext
------------------------------