Stored calculate value keeps changing

I have a form on central with a calculated field which gets displayed to users to be noted and passed along to other team members for their activities as well as reporting purposes. While testing the forms, I noticed that the initial values (results of the calculate) that were displayed while I was filling the form on ODK Collect were not the same as the values that were displayed under submissions on ODK Central. I retrieved the sent forms from ODK Collect only to find a completely different set of values yet again.

The calculated field in the form uses the term concat('QT-', substr(${zone},0,3),'-',format-date-time(now(),'%y%n%d%3')) and is displayed in a note as Quality Test N°: ${test_id}.

From my observations, it appears the calculation is re-evaluated each time the saved form is opened. Thus resulting in the different values each time it is opened. Is there a way I can stop this behaviour? Kindly find screenshots below.

xlsform definition

initial values displayed while filling form on ODK Collect
image

values as seen on ODK Central
Central values

Any insights would be greatly appreciated.

You could use once [docs] in the calculate so that it doesn't ever recalculate.

However as you also have another field in the concat (zone), that will be blank as the calculate will evaulate once on form open.

So instead, you could either;

  • add a trigger [docs] column and in the calculate field put ${zone}, so whenever that field is updated, the calculate runs. This will mean that the time value in the string will change each time the field is modified
  • create a separate calculate field eg start_time and have it calculate as once(format-date-time(now(),'%y%n%d%3')), then use that in your concat as concat('QT-', substr(${zone},0,3),'-',${start_time}), then no matter what happens in the form, the timestamp value will be fixed to the value evaluated on form open.
2 Likes

Thanks a ton for your suggestion. Sad news though, the value still changed when it reached Central and still changes when I open the submitted form.
You may find screenshots from the app and Central below.
PS: ODK Collect screenshots were taken successively and still had different values each time.


In the end, @ahblake still saved the day with this.
For anyone who faces a similar issue, I was able to get the ID to stay the same from filling the form in, to submitted to Central as well as reopening the sent form on ODK Collect with the definition below.