Can I set the "Default Response:" field of a numerical question to be the current year?

I have created a form that asks the year for which the data are relevant. I would like to set this field to have the current year as default value. For current year I mean dynamically set checking today’s date. The same should be done for the field of the week number.

Can it be done?

Thanks

Hello @andrea_ageon
Why not use date type with appearance year? You will get the current year preselected in the year (date) widget.
(You could limit the year range with a constraint.)

Otherwise you may use today() for current date on edit/save or ${today} metadata for first save and extract the year with the format-date function. See https://getodk.github.io/xforms-spec/#fn:today and
https://getodk.github.io/xforms-spec/#fn:format-date.

If the form is first filled/saved on 31/12/2020 but edited later on 01/01/2021 (before or after submission), what year do you want to get?? 2020 or 2021??

1 Like