Survey123 Connect: If question A is answered "yes", populate Question B with a calculation; otherwise leave it blank

5298
15
05-08-2018 08:25 AM
MatthewCarey
Occasional Contributor

In Survey123 Connect (2.6.4) I'm struggling with getting the form to perform a calculation in a question only if I answer yes to an earlier question.

I have a select_one yes_no question ({samples}) which is "Did you take samples today?"

If the answer is yes, I would like it to generate a sample number (text, in the field sample_coll_no) which concatenates text that's already been entered by the user such as county code, target pest, and date. It has this in the calculation column: ${county}+"-"+${targetsci} ..... and so on.

So when, using the 'relevant' column, I make sample_coll_no relevant only when ${samples} = 'yes', or make the group that it's in relevant only when ${samples} = 'yes', it doesn't populate it in the form; there doesn't seem to be a triggering event that would make that happen.

If I make the 'relevant' column blank for the sample number question, it performs the calculation whether or not the "did  you take samples" question is answered yes or no. And I don't want a sample number filled out when none was taken.

I'm not sure if it makes a difference but this survey is for filling in fields in a related table; the main point feature layer is trap locations and this related table is for the site visits; there will be multiple site visits for each site/trap. 

Can anyone suggest a different approach to my problem?  It seems like a somewhat standard thing that I'm trying to achieve but somehow I'm not getting there.

Thanks!

0 Kudos
15 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Matthew,

It sounds like you are running up against a known issue with Survey123 - when a question with a calculation becomes relevant, the calculation is not being triggered. We plan to fix this; in the meantime this can be worked around by having the user click on the text box to 'visit' the question and then press the 'recalculate' button (two green arrows making a circle) once that appears to the right of the question.

by Anonymous User
Not applicable

Oh NO!! Any ETA on when this will be fixed? After struggling with this for a few days I was happy to see your answer, but very sad to see it is without a fix.

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Pam,

This issue was addressed last summer (3.0 release).  Are you still seeing this behavior?  If so, can you share your form?

0 Kudos
by Anonymous User
Not applicable

Hi James,

I'm using Connect ver 3.1.126 and the iOS Survey123 app ver 3.3.64.

In the attached file I have a group of relevant clauses and if(selected....) statements. I found that if I removed the relevant clauses, the if-statements would calculate after I clicked each of the blue arrow circles next to the questions in the iOS app. The Status question only worked if the relevant clauses were gone as well. With the clauses present, a "D" would get entered correctly, but after uploading the survey to my online map, that point on the map simply disappears (the record exists in the database).

0 Kudos
by Anonymous User
Not applicable

Hi James - any news on this? Were you able to make sense of the form xls?

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Pam,

In your form, your questions that have a relevant statement to hide when 'Unimproved' is selected also have a calculation to set the value when 'Unimproved' is selected.  When question is not relevant, it has a null value; if there is a value in the question already it is emptied out and cannot be set via calculation.  

0 Kudos
by Anonymous User
Not applicable

Thanks James - I still can't get the Status field to symbolize correctly in the online map if I leave all of those questions with a null value. The points with Status='D' and all the other questions null disappear off the map, but are visible in the table.

0 Kudos
by Anonymous User
Not applicable

I still don't think this function really has been addressed in Survey123. If I allow a bunch of questions to remain null, the Status field doesn't work correctly, and if I leave out the calculations, I'm stuck with having to tap on all the arrow-circles to complete the survey.

So at this point I'm moving on with the clunky arrow-circle version (at least with that one the Status field works) and notifying my clients that we've run into another limitation of Survey123.

Thanks for trying to help, though.

0 Kudos
DougBrowning
MVP Esteemed Contributor

I see some commas in your Label field.  This can mess up your lists and may be your issue.  Remove all commas.

I also would try if(string-length(${StructureType})!='','D', 'I') instead.

    Why do you use !=D here but then use selected() everywhere else?  Just use if(${StructureType = '3'), 1, 0)

For your calcs I have had much better luck doing this

if(${StructureType = '3'), 1, 0) and then set the bind field (NOT esri bind) to int.

Then get right of all the int() in your score calc.  I have found this does not work.

It could be that the '' is breaking your Score and causing issues.

Wait I see now that all of those are list choices.  Hmm does score actually work?  You may need a second field for that.

0 Kudos