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

5268
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
JasonJordan00
Occasional Contributor

Hi James, I'm using  3.5 and I'm still seeing this behavior. I have a hidden field and if it becomes relevant, I want it to return one of two values, otherwise leave the original data in the field (since we heavily open past surveys up in the Inbox). 

I can't share my form but I'll show the relevant and calculation columns.

Relevant                              Calculation

${tflOnsiteStatus}!=''if(${tflOnsiteStatus}='No Issue','No Issue','Unresolved')

No matter what, it always returns "Unresolved", even if tflOnsiteStatus is blank. I have tried several different relevant expressions to see if any worked.

0 Kudos
DougBrowning
MVP Esteemed Contributor

Often when people have this issue they are checking the label value and not the Name value.  Since you have a space in there I wonder of that is it.

0 Kudos
JasonJordan00
Occasional Contributor

Thanks for the suggestion but I should have clarified. The label and name values are the same. The calculation itself works. The problem is is just runs regardless if its supposed to be relevant or not.

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Jason,

Based on your description, I would expect it to return 'Unresolved' if tflOnsiteStatus is blank.  The built-in if() function cannot preserve an existing value (i.e., 'replace this only if this condition').

0 Kudos
MichaelDepow
New Contributor

Hey James I have question for you if you have the time.  I have a select_one question called select_one normalCircum and I also have that in my name column normalCircum  

 

In my choices tab I have normalCircum and 2 options for it Yes and No.  What I want to happen is when you select No a text bar appears to allow you to explain why.  Do you know how I can do this?  I've attached some pictures to help hopefully 

20230418_133450.jpg

20230418_133459.jpg

20230418_133524.jpg

0 Kudos
MatthewCarey
Occasional Contributor

Hi James,

Thanks for the quick reply, much appreciated. Unfortunately in Survey123 on my iPhone I've been having trouble getting the 'recalculate' button to appear, I couldn't get it to work as you describe. The only time it would come up was when I'd added a second site visit and then erased it again, which did force the calculation in the sample_coll_no field to happen. Then when I erased a character from the end of the calculated string, the recalculate button appeared.

Other than that it's very reluctant to appear. Am I doing something non-standard, perhaps?

0 Kudos