Welcome to the LimeSurvey Community Forum

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

Can I get an answer value by the name of a question (as string) in EM?

  • orvil
  • orvil's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
10 years 1 month ago - 10 years 1 month ago #105791 by orvil
Hi all,

thanks to EM it is easy to get the answer of a question for further processing, like
{if(Q1_SQ001=="42","got it!","try again")

but: is there a way to get an answer value by having the question code (i.e. "Q1_SQ001") itself as the result if a calculation? Like
{if({QX.NAOK}=="42","got it!","try again")

where the content of QX.NAOK is "Q1_SQ001".

I've tried it in the way above with nested paranthesis, unfortunately without success.

Best regards/Beste Grüße,
O. Villani
Last edit: 10 years 1 month ago by orvil.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 month ago #105793 by DenisChenu
{if(Q1_SQ001.NAOK=="42","got it!","try again")
{if(Q1_SQ001.shown=="42",Q1_SQ001.shown,"try again")

etc ...

With EM : all part without quote are variable.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • orvil
  • orvil's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
10 years 1 month ago #105799 by orvil
Hi,

thanks for your reply. Of course, all parts without qoute are variable, unfortunately I don't need the result of the if-statement as a variable. The tricky thing for me is in the left part of the equation {if({QX.NAOK}...

The problem is:
- I'm having the name of a question (eg.: Q1) stored as a result of a calculation in another question (let's say in QX).
- Now I'd like to access the answer to Q1 by using the calculation result of QX

An example:
The content of QX is "Q1_SQ001" (a string, internally calculated by EM)
The content of Q1_SQ001 will may be "42" (or anything else, edited by a participant, but at survey creation time I don't know if I will have to look for Q1_SQ001 or Q1_SQ002 or Q2_SQ001... => this will be stored in QX)

That is why I'd like to access the result of Q1_SQ001 via indirecet reference of QX.

I hope that's not too confusing :sick:

Best regards/Beste Grüße,
O. Villani
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 month ago #105803 by DenisChenu
Hi,

{if({QX.NAOK} : no, don't use 2 times {{ for EM, just one.

Can you provide a little lss file for example ?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • orvil
  • orvil's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
10 years 1 month ago #105805 by orvil
Yes, good idea. I'll create an example lss!

Best regards/Beste Grüße,
O. Villani
The topic has been locked.
  • orvil
  • orvil's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
10 years 1 month ago - 10 years 1 month ago #105810 by orvil
Hi Denis,

here is a hopefully understandable example of what is meant.

As you will find in the description: there is a way to avoid indirect referencing, but it would bei pain :woohoo: :woohoo: :woohoo: for editing the survey and may be pain for the serverload.

THX THX THX

PS.: UUPS the helptext of the first question is wrong. It should be ...will be either "QY" or "QZ"

Best regards/Beste Grüße,
O. Villani
Last edit: 10 years 1 month ago by orvil.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 month ago - 10 years 1 month ago #105835 by DenisChenu
Yes, no quote.

BUT : you can not set default value in the same page : this need to be on different page. Because : EM in same page update HTML, and can not updated .

But here, because you have dfault value in QY, you can use:
Code:
{if(1==1,QY.NAOK,QZ.NAOK)}
But, if you do:
Code:
{if(QY.NAOK>1,QY.NAOK,QZ.NAOK)}
The response are prefilled by 24 and not 48 : because when page start : QY.NAOK is empty.

if you use 'QY.NAOK' or "QY.NAOK" : EM don't appply here.
The remove the quote , and it's OK.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 10 years 1 month ago by DenisChenu.
The topic has been locked.
  • orvil
  • orvil's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
10 years 1 month ago #105846 by orvil
Sorry,

I'm confused and can't catch your point. How does this match the problem to adress indirectly?

Best regards/Beste Grüße,
O. Villani
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 month ago - 10 years 1 month ago #105858 by tpartner
I think that with Expression Manager, as with JavaScript, you cannot have dynamic variable names.

You cannot take the VALUE of a variable and use it to create/modify another variable NAME.


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 1 month ago by tpartner.
The topic has been locked.
  • orvil
  • orvil's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
10 years 1 month ago #105876 by orvil
Hallo Tony,

thanks for your reply - I'm afraid you are right. My ulterior motive was it's may be like php.
So I have to follow another path - not that elegant, but hopefully with more success!

Thank to all for your effort!

Best regards/Beste Grüße,
O. Villani
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose