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:
Here are the "choices":
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
Solved! Go to Solution.
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):
More on conditional elements can be found here.
Hope this is useful
Best,
Jim
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")
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):
More on conditional elements can be found here.
Hope this is useful
Best,
Jim
Many thanks @Jim-Moore 🙂