Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

LimeSurvey 7 - How to include selected options from a Multiple Choice question i

More
2 weeks 6 days ago #274727 by asanacori
Hello,I am using LimeSurvey 7 and I am customizing the admin notification email template (the email sent to administrators after a respondent submits the survey).I have a Multiple Choice question with the following settings:
  • Question code: ReqAmm
  • Subquestion codes: SQ001, SQ002, SQ003, etc.
 My goal is to display in the email only the options selected by the respondent.I tried using ExpressionScript such as:<ul>{if(ReqAmm_SQ001 == 'Y', join('<li>', ReqAmm_SQ001.question, '</li>'), '')}{if(ReqAmm_SQ002 == 'Y', join('<li>', ReqAmm_SQ002.question, '</li>'), '')}{if(ReqAmm_SQ003 == 'Y', join('<li>', ReqAmm_SQ003.question, '</li>'), '')}</ul>I also tried placeholders such as:    {ReqAmm}     {ReqAmm.shown}    {ReqAmm_SQ001}However, none of these are evaluated, the email contains the expressions exactly as written (literal text), for example:{ReqAmm.shown} {ReqAmm_SQ001}instead of the expected values.My questions are:1. What is the correct way to access the selected answers of a Multiple Choice question in that email?2. Is there a specific placeholder or syntax that should be used for question code ReqAmm and subquestions SQ001, SQ002, etc.? Any example would be greatly appreciated.Thank you!=====================================
Please help us help you and fill where relevant:
Your LimeSurvey version: 7
Own server or LimeSurvey hosting: my server

Please Log in to join the conversation.

More
2 weeks 6 days ago #274730 by holch
For this kind of question it is always helpful to include a small sample survey that shows the structure of this question. Because the error could be in the details.

And before you start with the email, which is a lot more difficult to debug, make sure that your code works in the survey itself (easier to debug). Create a text display question after the respective question and try to display what you want in the email there first.

You'll have a lot quicker "feedback" on what works. That's how I would approach this.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.

Please Log in to join the conversation.

More
2 weeks 5 days ago - 2 weeks 5 days ago #274731 by Joffm
Hi,
I do not see an issue.


1. the simple "list" function
2. IF function with "join" and "br/"
3. IF function with "ul" and "li"


And furthermore you can use all elements of bootstrap 5. Have a look at "listgroup", like
<ul class="list-group">
    {if(Q1_1=="Y",'<li class="list-group-item">'+Q1_1.shown+'</li>','')}
    {if(Q1_2=="Y",'<li class="list-group-item">'+Q1_2.shown+'</li>','')}
    {if(Q1_3=="Y",'<li class="list-group-item">'+Q1_3.shown+'</li>','')}
    {if(Q1_4=="Y",'<li class="list-group-item">'+Q1_4.shown+'</li>','')}
    {if(Q1_5=="Y",'<li class="list-group-item">'+Q1_5.shown+'</li>','')}
</ul>
 
And I found a real short solution with "listifop"
<ul><li>
{listifop( "code", "==", "Y", "shown", "</li><li>", that.Q1.sgqa)}
</ul>

So it is necessary that you send a lss export of your survey (this relevant questioon) and mention the exact version of your installation.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 weeks 5 days ago by Joffm.

Please Log in to join the conversation.

More
2 weeks 1 day ago #274751 by asanacori
Hi all.
After several tests, I found a solution that works reliably in the LimeSurvey 7 administrator notification email template for displaying only the selected options of a Multiple Choice question on GMail message.
My question code is
Code:
Q1
, with subquestions
Code:
Q1_1
,
Code:
Q1_2
,
Code:
Q1_3
,
Code:
Q1_4, ...
The most effective approach I found is to explicitly test each subquestion and display its corresponding
Code:
.shown
value only when the answer is
Code:
"Y"
:

1 {if(Q1_1=="Y","1. " + Q1_1.shown + "<br>","")}
2 {if(Q1_2=="Y","2. " + Q1_2.shown + "<br>","")}
3 {if(Q1_3=="Y","3. " + Q1_3.shown + "<br>","")}
4 {if(Q1_4=="Y","4. " + Q1_4.shown + "<br>","")}
5 ...............................

This produces an output such as:
1. Answer 1
2. Answer 2
4. Answer 4

Only the options selected by the respondent are displayed, while unselected options are omitted.

Although this approach requires manually defining each subquestion, it is currently the most satisfactory and reliable solution I have found for administrator notification emails.

I would still be interested to know whether there is a more generic or dynamic way to retrieve and display only the selected options of a Multiple Choice question without having to reference every subquestion individually.

Good day.

Please Log in to join the conversation.

More
2 weeks 1 day ago #274752 by Joffm
Hi,
this is the same structure you already showed. Instead of the "joining" function you used the "+" operator, what is more or less the same. Now you still don't know why your "join" approach didn't work.
Therefore a lss export is always recommended that we see where you inserted a small mistake (sometimes only a typo)

And to answer your last paragraph (generic, dynamic):
I mentioned the "listifop" function and showed the necessary code to get an output as an "unordered list". 
Did you try it?
You may read the manual about the "implemented functions" 

Joffm 
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose