Welcome, Guest
Username: Password: Remember me

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

Can I get an answer value by the name of a question (as string) in EM? 7 months 3 weeks ago #105791

  • orvil
  • orvil's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 104
  • Thank you received: 4
  • Karma: 4
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: 7 months 3 weeks ago by orvil.
The administrator has disabled public write access.

Can I get an answer value by the name of a question (as string) in EM? 7 months 3 weeks ago #105793

  • DenisChenu
  • DenisChenu's Avatar
  • NOW ONLINE
  • Moderator Lime
  • Posts: 6471
  • Thank you received: 853
  • Karma: 254
{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.
The administrator has disabled public write access.

Can I get an answer value by the name of a question (as string) in EM? 7 months 3 weeks ago #105799

  • orvil
  • orvil's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 104
  • Thank you received: 4
  • Karma: 4
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 administrator has disabled public write access.

Can I get an answer value by the name of a question (as string) in EM? 7 months 3 weeks ago #105803

  • DenisChenu
  • DenisChenu's Avatar
  • NOW ONLINE
  • Moderator Lime
  • Posts: 6471
  • Thank you received: 853
  • Karma: 254
Hi,

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

Can you provide a little lss file for example ?
The administrator has disabled public write access.

Can I get an answer value by the name of a question (as string) in EM? 7 months 3 weeks ago #105805

  • orvil
  • orvil's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 104
  • Thank you received: 4
  • Karma: 4
Yes, good idea. I'll create an example lss!
Best regards/Beste Grüße,
O. Villani
The administrator has disabled public write access.

Can I get an answer value by the name of a question (as string) in EM? 7 months 3 weeks ago #105810

  • orvil
  • orvil's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 104
  • Thank you received: 4
  • Karma: 4
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"
Attachments:
Best regards/Beste Grüße,
O. Villani
Last Edit: 7 months 3 weeks ago by orvil.
The administrator has disabled public write access.

Can I get an answer value by the name of a question (as string) in EM? 7 months 3 weeks ago #105835

  • DenisChenu
  • DenisChenu's Avatar
  • NOW ONLINE
  • Moderator Lime
  • Posts: 6471
  • Thank you received: 853
  • Karma: 254
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:
{if(1==1,QY.NAOK,QZ.NAOK)}
But, if you do:
{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.
Last Edit: 7 months 3 weeks ago by DenisChenu.
The administrator has disabled public write access.

Can I get an answer value by the name of a question (as string) in EM? 7 months 3 weeks ago #105846

  • orvil
  • orvil's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 104
  • Thank you received: 4
  • Karma: 4
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 administrator has disabled public write access.

Can I get an answer value by the name of a question (as string) in EM? 7 months 3 weeks ago #105858

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4293
  • Thank you received: 810
  • Karma: 373
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 7 months 3 weeks ago by tpartner.
The administrator has disabled public write access.

Can I get an answer value by the name of a question (as string) in EM? 7 months 3 weeks ago #105876

  • orvil
  • orvil's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 104
  • Thank you received: 4
  • Karma: 4
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 administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.219 seconds
Donation Image