Relationship between repeat rows

266
7
10-09-2017 01:47 AM
Highlighted
New Contributor III

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 ?

Reply
0 Kudos
7 Replies
Highlighted
Esri Esteemed Contributor

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.

Reply
0 Kudos
Highlighted
New Contributor III

Thank you very much James you saved my day, however I can't find the attached file.

Best regards.

Reply
0 Kudos
Highlighted
Esri Esteemed Contributor

You should be able to see it at the bottom of my first reply.

The worksheet looks like (deleting unneeded columns):

typenamelabelconstraintconstraint_messagecalculationbind::typebind::esri:fieldType
textExampleExample
begin repeatpeoplePeople
textnameName
select_one roleroleRole
select_one statusstatusStatus
integerageAge
calculateparentageparentageif(selected(${role}, 'child'), '', ${age})null
calculatechildagechildageif(selected(${role}, 'child'), ${age}, '')null
calculatehusband_marriedif(selected(${role}, 'husband') and selected(${status}, 'married'), 1, 0)integer
calculatewife_marriedif(selected(${role}, 'wife') and selected(${status}, 'married'), 1, 0)integer
end repeat
calculatenumhusbandnumhusbandsum(${husband_married})null
calculatenumwifenumwife. = ${numhusband}Invalid marriage information0null
calculateminparentageminparentagemin(${parentage})null
calculatemaxchildagemaxchildage. < ${parentage}A child must be younger than a parent!max(${childage})null
Reply
0 Kudos
Highlighted
New Contributor III
Hi James,
After some experimentations I found that this does not help very much. Since the validation is done after collecting all the individuals and not individual by individual this makes the alert message very confusing.
Now I am looking for using collector besides survey123 to execute this survey when Collector will be used to collect individuals high level data (age, marital status,...) and then each individual will have a url to call survey123 for collecting detailed informations. 
For this I have two questions
1. Does collector support cheking this kind of relationship (chield/parent, married,...)?
2. When using the url to start survey123, then collecting the data, then closing the survey and reopening it through the same url will we find the already collected data or a new survey will be created?
Best regards
Reply
0 Kudos
Highlighted
Esri Esteemed Contributor

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.

Reply
0 Kudos
Highlighted
New Contributor III

Thanks for your prompt reply.

2) is really disappointing.

Reply
0 Kudos
Highlighted
New Contributor III

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

Reply
0 Kudos