I have a survey that asks users to input the number of animals they see during surveys. Sometimes, surveyors want to enter specific details about certain focal animals, such as whether the animal had an eartag. In some cases, they know that they saw a group of animals, but were only focused on finding a particular individual, or family, within that group. Therefore, in the main part of the survey, I ask users to input the entire group size, and the number of focal animals they want to enter detailed information about.
Let's assume that we have a group size of 5, with only 1 focal animal, "George". This means that I want two records in my repeat: 1 for the focal animal, and one summarizing the remaining 4 animals. I have set the number of records in my repeat dynamically by setting "repeat_count" in my form to ${number_records}. In this example, ${number_records} is two.
If the user is filling out the first record, I want them to answer a number of questions, such as whether the animal has an ear tag. I want to automatically calculate the value of the last record for the remaining 4 animals, to say that ear_tag_observed is 'unknown'. I do not want it to be null. I also do not want to set a default value for ear_tag_observed, because I want to ensure high data quality by forcing users to enter all required fields. I don't want a user to have to enter 'unknown' for non-focal animal records - it should be automatically filled out to save precious time in the field!
My solution, which works perfectly to store the data, is to have users select 'yes', 'no', or 'unknown' in the field 'ear_tag_observed_c'. This field is not stored. A second field, which is stored, says "if this is the last record in the repeat, enter 'unknown' into the 'ear_tag_observed' field, otherwise, make 'ear_tag_observed' equal to the user-entered value."
The only kink is that when users go to edit the data in the repeats in the web app, the values of ear_tag_observed are blank for all focal animals! This is because the calculated field is not stored (and I don't want to store it).
I've tried to get help with ChatGPT, but keep running into issues with not being able to use expressions in the default field, or it wanting me to create dependency cycles.
Is there a way for me to get around this issue? Again, my requirements are:
- users should not have to enter data for non-focal animals - it should be calculated
- data value for 'ear_tag_observed' should be 'unknown', NOT null, for non-focal animals
- I don't want to store the calculate fields in my database
- data must be retained for editing in the repeat table for focal animals in the S123 web app.
Here's an example of how that 'ear_tag_observed' field is currently calculated in my survey:
| type | name | label | hint | appearance | required | readonly | required_message | calculation | relevant | bind::esri:fieldType |
| integer | number_animals | Number of animals | The number of animals this record is summarizing. | | | yes | | if(position(..) < ${number_records}, 1, ${number_remaining_animals}) | | |
| select_one list_yes_no_unknown | ear_tag_observed_c | Calculate | | horizontal-compact | yes | | This is a required question | | position(..) < ${number_records} | null |
| select_one list_yes_no_unknown | ear_tag_observed | Ear tag observed? | Only this field is stored. | hidden | | | | if(position(..) < ${number_records}, ${ear_tag_observed_c}, 'unknown') | | |