Conditional report elements

You can show or hide elements of a report conditionally using if statements. You can use the if statement by typing an expression in the starting ${if expression} placeholder, with ${/} denoting the end of the conditional segment. Some examples of if statements that you can use to show or hide parts of a report are the following:

  • ${if photo1} displays the section only if the photo1 question has been answered.
  • ${if integer1>0} displays the section only if the answer to the integer1 question is a positive number.
  • ${if ((geopoint1 | getValue:"y")>0)} displays the section only if the geopoint is in the northern hemisphere.
  • ${if multiple_choice1 | selected:"A"} displays the section only if the multiple choice question has had the choice A selected.
  • ${if (repeat1 | getValue:"count")>=3} displays the section only if repeat1 contains three or more records.

In the following example, the text in the second line will only appear in the report if high is selected for the priority select one question:

${if priority | selected:"high"}
High priority issues must be addressed within seven days.
${/}

To determine whether a response contains a value for a question, only use an if statement referring to the field name directly with no other operators, for example, ${if photo1}. This format ensures that empty strings, null values, and undefined values are all considered empty values. This format applies to string, number, date, and attachment field types. When this format is used with repeats, the section will appear as long as there is at least one instance in the repeat.

To use conditional statements with date and time questions, perform calculations using Epoch time (milliseconds elapsed since January 1, 1970). For example, ${if (date1|getValue:"") < 1602735375000} displays the section only if the value in the date field is before October 14, 2020. Report syntax doesn't have an equivalent to the XLSForm today() or now() functions, so it's impossible to compose a conditional statement for times relative to when the report was printed.

The following logical operators are supported in if statements:

OperatorDescription

||

True if one of two statements returns true

&&

True if both given statements return true

!

True if the statement is not true

==

True if the two given values are equal to each other

!=

True if the two given values are not equal to each other

>

Evaluates whether the first value is greater than the second value

>=

Evaluates whether the first value is greater than or equal to the second value

<

Evaluates whether the first value is less than the second value

<=

Evaluates whether the first value is less than or equal to the second value

A table can be used in a report to present individual repeat records or a summary of records. To use a conditional statement to hide a table that has no values, the start and end placeholders must be placed outside of the table, immediately before and after the table. To use a conditional statement to show only the header row of the table when the table has no values, the start placeholder must be placed inside the first cell of the table, and the end placeholder must be placed inside the last cell of the table.