Conditionals in Survey 123 Reports

2753
12
11-07-2018 01:21 PM
DavidJones19
New Contributor

I found very little in the documentation. What I am trying to do is generate a report and show the questions and answers only if a certain single choice answer is given. I downloaded the template

1. Question text was here?

${field_5}

First I tried 

${if field_5=choice1}

1. Question text was here?

${field_5}

${/}

This generated a syntax error. Next I tried 

${if field_5|selected:"choice1"}

1. Question text was here?

${field_5}

${/}

and the report seems like it is generating but never gets above 0%. 

0 Kudos
12 Replies
StephenM
Occasional Contributor II

Testing if two values are equal should use two equal signs. That may have been why the first conditional gave a syntax error.

erica_tefft
Occasional Contributor III

Just curious if you ever figured out a solution to this, as I am having a similar issue. I use the syntax -

${Standing_Location} (${if Corner_Landmarks==“other_sign”}${LD_Other_Sign_Details}${/}

With the example that I'm testing the record has Corner_Landmarks equal to other_sign, and details filled out in LD_Other_Sign_Details, however nothing prints. All I get is the result of the Standing_Location field.

Erica
0 Kudos
StephenM
Occasional Contributor II

I saw that you got a reply in another thread that said this isn't supported, but this worked for me:

In my report template (the selected record has city = "Los Angeles"):

${test_yes_no} (${if city=="Los Angeles"}${time_stamp}${/})
${test_yes_no} (${if city=="San Francisco"}${time_stamp}${/})

Output in the generated report:

No (Oct 5, 2018)
No ()

I thought maybe there could be an issue with field length or something, but I also tested this with a field containing a 450-character description and it worked.

What's the data type of the LD_Other_Sign_Details field?

Edited to add: This looks like the most detailed documentation that discusses this type of conditional statement: 

https://community.esri.com/groups/survey123/blog/2018/07/06/bull-release-30

0 Kudos
erica_tefft
Occasional Contributor III

Hi Stephen,

The LD_Other_Sign_Details field is a text field; this only shows up when the answer to Corner Landmarks (a select multiple question type) is equal to "other_sign". Is your city field a select one question type? Part of me wonders if the fact that my Corner Landmarks question is select multiple is causing this to fail.

But yes - I have received responses say this isn't possible/wont be possible, which is disappointing. I see no difference in our syntax that would cause your statement to work, and mine to fail.

I've also read the https://community.esri.com/groups/survey123/blog/2018/07/06/bull-release-30, which is what led me to believe this was possible in the first place.

Erica
0 Kudos
StephenM
Occasional Contributor II

Ah, the question being a select multiple is probably the issue. I tested the conditional with text and select one questions. I don't think you can isolate selections from a select multiple question. You can use select multiple questions in conditionals, but you have to test for the whole string that's returned by the field name code in the template (selections from select multiple questions are returned as a comma-separated string).

I tried setting up an "if" statement with multiple "or" operators to test for multiple combinations of selections, but it seems that everything beyond the first "or" is ignored.

For example, given a record with color_sel = "blue , white , green":

${if color_sel==”blue , white” || color_sel==”blue , white , green” || color_sel==”blue , green” || color_sel==”blue”}${details}${/}

${if color_sel==”blue” || color_sel==”blue , white” || color_sel==”blue , green” || color_sel==” blue , white , green”}${details}${/}

The first statement displays the contents of the details field, but the second does not.

Philip-Wilson
Esri Frequent Contributor

Hi Erica,

I have updated my replies over on your other post regarding conditional if statements being supported with a link to the documentation. Sorry about that. I think the issue you are encountering as pointed out by Stephen is that if you are using a select multiple, the entire string value needs to match, as it will be a comma separated list.

Phil.

Philip-Wilson
Esri Frequent Contributor

Hi David,

Documentation on conditional if statements in the feature report custom templates can be found here: Feature report templates—Survey123 for ArcGIS | ArcGIS 

Regards,

Phil.

0 Kudos
OrçunAkkay
New Contributor II

Hello Philip, I have an issue with conditional statements. I can use if conditions but the problem is when a field is hidden, the other field which is placed on the next line does not take the place of the hidden field. For example;

Situation 1     Situation 2

Field 1         -                        when field 1 is hidden, field 2 is placed at the second line
Field 2         - Field 2                     

Is there any way to prevent it?                                                                                                      

0 Kudos
Philip-Wilson
Esri Frequent Contributor

Hi Orcun,

Can you provide a screenshot of how it looks in the form, and also if you can share a copy of your xlsx file that would be very helpful. I just want to make sure what you are describing is what I am thinking, and it is working as expected.

Regards,

Phil.

0 Kudos