CommCare Logic Syntax: Syntax for Null or Missing in CommCare

What kind of syntax does CommCare use to identify missingness? For example, if you want to write logic such that a question only appears if the value of another question is null, how would you write it?

Would it be variable=''?

In general, a blank string ('') is a good stand-in for an empty or missing value.

#form/other_question = ''

would work in a display condition to only ask it if another question's value is missing.

There's one additional level of nuance which is generally not important, but might matter for you based on what you are asking.

The engine is capable of identifying the difference between a question which is blank (a text question, for example, would be blank if it was asked to a user but a user did not enter a value) and a question which is missing (was not asked to the user because its display condition evaluated to false, or it is in a group whose display condition evaluated to false).

In either of those two cases, a reference to the question will match the empty string (''), so if your use case doesn't need to differentiate between those two, you should use that.

If, however, you need to further trigger logic based on a missing question, you can use the count() function to identify whether the question exists in the form's data model.

count(#form/other_question) = 0

This condition will trigger only when the other question was never asked due to display conditions.


1 Like