CommCare – How to Get Timestamp for Exact Time a Question is Answered

commcare

I would like to know the exact time the user answers a specific question in the form. Is this possible using the now() function in CommCare?

For example, if i wanted to know what time the question alis_favorite_color is aswered, and I created a hidden value alis_favorite_color_time and set the display condition of that HV as alis_favorite_color != '' and the calculate condition as double(now()), what will the output of the alis_favorite_color_time HV? Will it be the time at which the display condition evaluates to TRUE, or will it be the time of completion of the form?

Best Answer

now() will be calculated at various times (form start, form validation, etc) outside of your control.

Calculate conditions are (somewhat unintuitively) processed independently of their display conditions, so the app doesn't delay processing the now() function until it is relevant to the form.

The only way to accomplish what you are describing in the current app is to create a repeat which starts with 0 elements, then conditionally sets its count to 1 element when the question is answered, and setting the time condition in the default value of an element in that repeat.

That repeat will need at least one question inside of it (not a hidden value), but that question can have a false() display condition.

The user will also still need to navigate over the repeat. IE: the now() won't be triggered until the user swipes over where the repeat is in the form's structure.