Select to view content in your preferred language

Survey123 Report Template If Statement with select_one question

4853
3
Jump to solution
01-21-2021 07:27 AM
by Anonymous User
Not applicable

Hi all,

I am trying to use an IF statement to display different chunks of text based on the answers to a question.

I have a select_one question which is in a table-list group:

BenBlowers_0-1611242436794.png

Here are the "choices":

BenBlowers_1-1611242488363.png

And here is the if statement I am writing in my Report Template, but it returns no data or text whatsoever:

${if Unknown==”Emergence”}${no_of_bats}x Unknown bat (${frequency}kHZ) emerged at ${recording_time} (track number ${track_number})${/}

${if Unknown==”Return”}${no_of_bats}x Unknown bat (${frequency}kHZ) returned at ${recording_time} (track number ${track_number})${/}

${if Common_pipistrelle==”Emergence”}${no_of_bats}x Common pipistrelle bat(${frequency}kHZ) emerged at ${recording_time} (track number ${track_number})${/}

${if Common_pipistrelle==”Return”}${no_of_bats}x Common pipistrelle bat(${frequency}kHZ) returned at ${recording_time} (track number ${track_number})${/}

Does anyone know why my if statement is wrong?

Thanks,

Ben

1 Solution

Accepted Solutions
Jim-Moore
Esri Regular Contributor

Hi @Anonymous User 

Your syntax is almost there, however, for these expressions in a report template, you need to use the choice and question names (not their labels). For select_one questions you can also use the following 'selected:' syntax:

${if Unknown | selected:"emergence"}Your conditional text goes here.${/}

This is equivalent to:

${if Unknown == "emergence"}Your conditional text goes here.${/}

To check if a choice is not selected, you can use:

${if Unknown != "emergence"}Your conditional text goes here.${/}

If you haven't already seen it, there's a really useful quick reference that provides syntax examples for all the questions in your survey (see link on the Manage Templates dialog):

Report_quick_ref.png

More on conditional elements can be found here

Hope this is useful

Best,

Jim

View solution in original post

3 Replies
LeonardBarnhill
Frequent Contributor

Need more information.  The If statement is not formatted correctly but I do not have enough information to understand the intent. 

The format of the If statement should be If(selected(${fieldName},"select_one value"), what happens if true, what happens if false")

0 Kudos
Jim-Moore
Esri Regular Contributor

Hi @Anonymous User 

Your syntax is almost there, however, for these expressions in a report template, you need to use the choice and question names (not their labels). For select_one questions you can also use the following 'selected:' syntax:

${if Unknown | selected:"emergence"}Your conditional text goes here.${/}

This is equivalent to:

${if Unknown == "emergence"}Your conditional text goes here.${/}

To check if a choice is not selected, you can use:

${if Unknown != "emergence"}Your conditional text goes here.${/}

If you haven't already seen it, there's a really useful quick reference that provides syntax examples for all the questions in your survey (see link on the Manage Templates dialog):

Report_quick_ref.png

More on conditional elements can be found here

Hope this is useful

Best,

Jim

by Anonymous User
Not applicable

Many thanks @Jim-Moore 🙂

0 Kudos