Hello ODK Forum. I have been familiar with ODK programming for a few years, although this is my first ODK-related post.
I'm experiencing trouble when trying to have a pre-fill date type question with a year appearance (it just requires to register a year, not a YY-MM-DD value). The question which requires this is "When did you start working at [organization's name]?", and I would like to have it filled-in by default with the current year minus the number of years the respondent has within the organization he/she is currently working for, so enumerators would possibly go through this question fastly.
To get this, I programmed the following lines:
i) A line to calculate the current year minus the number of years the respondent in the organization:
type | name | calculation |
---|---|---|
calculate | year_start | int(substr(string(${today}),0,4))-round(${years_working},0) |
(Note that "today" is today's date and "years_working" is the number of years in the organization, which is a decimal type)
ii) A line which concatenates this with "-01-01":
type | name | calculation |
---|---|---|
calculate | date_default | concat(string(${year_start}),'-01-01') |
So the result of this calculation will be a date string which should be able to be read as the first day of January of the (likely) start year.
iii) Finally, I programmed the question which should be pre-filled as the following:
type | name | appearance | appearance | calculation |
---|---|---|---|---|
date | start | When did you start working at ${organization}? | year | ${date_default} |
I have tried this coding with Kobo Collect (v1.14.0a) and SurveyCTO Collect (v2.20). And something very strange I have noticed is that it actually works with Kobo Collect, but SurveyCTO shows an error message. For example, if the result of date_default is '2015-01-01', it displays: "2015-01-01 cannot be converted to a date value", and the same happens with other year values.
Have you ever ran into a similar issue?
Thanks very much in advance.
Luis Eduardo