Hello,
We are conducting a household survey where we collect information about the household and the individuals living in those households.
We survey individuals as a related table (repeat field) and we need to define constraints between them. For example if an individual is marked as married then his wife has to be marked as married and if they have children then the age of each one of those children must be inferior to the parents age, etc.
How can we define this kind of constraint between rows of a repeat table ?
Hi,
While you can't set up a relationship between entries in a repeat, you can create validation checks in the parent form based on the data in the repeat. I've created a survey that I think matches the constraints you asked about; see the attached file.
First, let's look at chile/parent ages - this is accomplished by having questions in the repeat that separates the age information for children and the age information for parents (mother/father) into two temporary questions (note that I used a esrifieldtype of null so that this data isn't saved). That lets me calculated the maximum child age and minimum parent age in the main part of the form; if the child age is larger than the parent age, a constraint rule prevents submission.
Similarly, I added a calculation that is populated when a husband is listed as married and one when a wife is listed as married; in the main form these are summed and compared.
Thank you very much James you saved my day, however I can't find the attached file.
Best regards.
You should be able to see it at the bottom of my first reply.
The worksheet looks like (deleting unneeded columns):
type | name | label | constraint | constraint_message | calculation | bind::type | bind::esri:fieldType |
text | Example | Example | |||||
begin repeat | people | People | |||||
text | name | Name | |||||
select_one role | role | Role | |||||
select_one status | status | Status | |||||
integer | age | Age | |||||
calculate | parentage | parentage | if(selected(${role}, 'child'), '', ${age}) | null | |||
calculate | childage | childage | if(selected(${role}, 'child'), ${age}, '') | null | |||
calculate | husband_married | if(selected(${role}, 'husband') and selected(${status}, 'married'), 1, 0) | integer | ||||
calculate | wife_married | if(selected(${role}, 'wife') and selected(${status}, 'married'), 1, 0) | integer | ||||
end repeat | |||||||
calculate | numhusband | numhusband | sum(${husband_married}) | null | |||
calculate | numwife | numwife | . = ${numhusband} | Invalid marriage information | 0 | null | |
calculate | minparentage | minparentage | min(${parentage}) | null | |||
calculate | maxchildage | maxchildage | . < ${parentage} | A child must be younger than a parent! | max(${childage}) | null |
Hi,
1) Collector does not have any data validation functionality that would check for this type of status
2) Currently opening Survey123 via a url will add a new entry only- Survey123 does not yet support opening a survey in edit mode.
Thanks for your prompt reply.
2) is really disappointing.
Hi James,
Will version 3.0 support opening a survey in edit mode ?
How about position(), join() and/or an indexed-repeat() to access data inside the repeat group ?
Best regards