Is there a way to prepopulate a field depending on the value of another field?

770
6
11-19-2019 01:56 PM
LaurenMcGarvey
New Contributor II

I have a survey to collect demographic data of collared ungulates.  Each observation of a collared ungulate is stored as a separate row in the database.  I am running into problems when there are multiple collared ungulates in a group because then the demographic data is repeated in the database.  I am trying to come up with a way to easily filter out repeated demographic data when needed.  I have a question asking if there are multiple collars in the group (name = multiple_collars) .  If the answer is "yes", a relevant question appears asking if this is the first collar surveyed in the group (name = collar_no).  If the collar is the first surveyed in the group, it is stored as a value of 1.  If the collar is the second surveyed in the group, it is stored as a value of 2.  What I would like to do is prepopulate collar_no with a value of 1 if there are not multiple collars in the group (multiple_collars = "no").  If there are multiple collars (multiple_collars = "yes"), then the user would define the collar_no value as 1 or 2 using the relevant question.  I would filter the data by values of 1 for collar_no to prevent repeated demographic data.  Does anyone know if this is possible? 

I have attached the xlsx form of my survey      

Tags (1)
0 Kudos
6 Replies
BenTurrell
Occasional Contributor III

Hey Lauren,

Is this the sort of thing you are after? 

if(selected(${multiple_collars }, 'no'), 1,0)

This would go into the calculation field of collar_num

I tried to open your survey but it had some errors and I couldn't get it working in Survey123. Let me know if I'm not on the right track!

Thanks,

Ben

LaurenMcGarvey
New Contributor II

Hi Ben,

I tried added this calculation to the collar_no field.  However, a value was not added when multiple_collars = "no".  Do you think it is not working because collar_no is relevant if multiple_collars ="yes"?.

I've tried attaching my xlsx form again. 

Thanks!

Lauren 

0 Kudos
DougBrowning
MVP Esteemed Contributor

When I field is hidden due to a relevant it gets a value of '' (blank).  So yes when you have it hidden due to relevant it has no value.  I would just remove the relevant.  Then they see it get an automatic no.  Or make it totally hidden using the type of hidden (versus a select).  No user input is needed so no reason to show it to the user.

LaurenMcGarvey
New Contributor II

Hi Doug,

User input is required if there are multiple collars.  If there are multiple collars, the user must define collar_no as 1 or 2.  If there are not multiple collars, I wanted the collar_no field to be automatically populated with a value of 1.

Thanks for your help!

Lauren   

0 Kudos
BenTurrell
Occasional Contributor III

Could you set the default value of multiple_collars to be 1?

DougBrowning
MVP Esteemed Contributor

I agree with Ben.  Do not hide it and then default to 1, then they can change it.  If you want you can have it flip to read only when no.