Select to view content in your preferred language

Problem in Survey123 basing default value of one question on condition of another

5545
7
07-16-2017 06:10 AM
NealBanerjee
Frequent Contributor

Hello,

I have an annoying issue in Survey123 that seem should be basic.  I am trying to populate the default "answer" (value) of one question based on an answer to a previous question.  In my case the first question (Q1)  is "Structure1_Type", which is a 'select_one' question.  The second question (Q2) that I am trying to populate default answer based on answer given to first question is "Structure1_Material", which is also a 'select_one' question.  Both questions are in a nested group named "Structure 1".

Basically, if user selects the a type="ABC" in Q1, I want default answer for Q2 to be "Metal", otherwise I want it to be "Concrete".  The conditional expression I am using is:

if(${Structure1_Type}='ABC', 'Metal', 'Concrete')

Initially I tried putting that expression into the 'Calculation'.  It does not give an error, but most of the questions in the Structure 1 group (i.e. Q1 and Q2 are no longer on the form).  If I put the expression in the default field, instead of showing the answer in Q2, it shows a greyed out copy of my expression with a line through it (suggestion expression is invalid). 

I even tried adding a separate note field named "kmeMaterial" and putting the calculation there first and then referencing it in the default field of Q2.  Interestingly, the value populates correctly in "kmeMaterial" but it gives the same greyed out expression with line in Q2 (where I want to actually store the permanent answer).

Attached is a screenshot that shows how the last trial looks in Survey123 Connect.  As you can see, "kmeMaterial" correctly shows an answer of 'Metal', however, the "Structure 1: Material" (i.e. Q2) has the issue.

I want to use similar logic in multiple places in my form, so this issue is hampering thing quite a bit. 

Any help/suggestions would be greatly appreciated!

Thanks

Neal

Survey123 Connect with Error

0 Kudos
7 Replies
by Anonymous User
Not applicable

Hi Neal,

Default values are populated when you first open the survey, for this reason default values can not contain calculations that reply on an answer to a previous question, as at the time of opening the survey these previous questions will not have been populated. Default values are best used as static values that you want populated the same every time you open the survey.

The correct way would be to put the calculations in the Calculation field and use the IF statements you highlight above against those questions you want to populate based on previous questions. Calculations are evaluated and populated every time an answer changes int he survey.

If you are able to upload your survey (xlsx file) so that we can take a closer look, if you are still having issues getting your calculations to work.

Regards,

Phil.

0 Kudos
NealBanerjee
Frequent Contributor

Hi Philip,

I think what you are suggesting is what I initially tried.  I added a separate row with question type of 'calculate', did the IF expression and then referenced that question in the calculate field of the material question that I am trying to auto-populate.  However, when I did that it seems to mess up the other questions in the same group.  Ill upload my survey.  Its got a bunch of other groups, questions, etc. by just trying to get the Structure1_Material thing to work

0 Kudos
by Anonymous User
Not applicable

Hi Neal,

Thanks for sharing your survey. I have had a quick look at your survey and noticed a few things.

Currently Survey123 does not support calculations on select_one question types, there is currently a feature enhancement in the backlog for this request. Therefore this is reason when you add a calculation to the Structure1_Material question you will notice the questions in that group do not appear in the survey. An alternative way to do this would be to use choice_filter function and assign the select_one choices with the structure type in the choices tab. The user will still need to select the answer from the dropdown, however they will be provided with a smaller list of options.

I noticed with your survey is you are using a select_one for the Number_of_Structures field. Select_ones are always treated as text fields. Given all the choices are integer, I would recommend using the field type as integer. Whilst I see you have set the esriFieldTypeInteger to this question, this only applies to the feature service created, the survey will still treat that field as text when using calculations etc.

One other thing I noticed is that you have used the relevant function to repeat the structure questions 5 times in the survey, and so the same with other questions throughout survey. Have you considered using repeats, so that you only have one set of questions for each type of group, and then depending on how many structures are input, the number of repeats will match. Note that this creates a related table in the feature service which may or may not have benefits depending on how you plan to use the data.

Regards,

Phil.

NealBanerjee
Frequent Contributor

Morning Phil,

I really appreciate you looking into my issue and even taking the time to give other recommendations.  Hopefully this will be something that is addressed in an upcoming release, since would be really useful.  I did look into the choice filter, but didnt quite work since some structure types can have variable materials while others cannot.  Ill check out your other recommendations too.

Again, many thanks on your help and support!

Neal

by Anonymous User
Not applicable

You might want to consider the pulldata() function also, as it allows the same functionality of populating multiple questions off the answer of one question. I use this function to answer 6 standard project ?'s; project name, site name, project lead, and more, from the user choosing the project number within the first question.

0 Kudos
NealBanerjee
Frequent Contributor

Thanks Mike - I am going to try this

0 Kudos
by Anonymous User
Not applicable

No worries. I hope this helps you out; I know it has helped us out tremendously.

0 Kudos