Welcome to the LimeSurvey Community Forum

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

using variables in admin mail notification

  • Siem
  • Siem's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 6 months ago - 8 years 6 months ago #135511 by Siem
In an admin mail notification I want to display some scores.
It would be very handy if I could use variables. These variables are not defined in the survey.
Below is an simple example, how would I do that?
Code:
{ $a = 5 } // nothing is printed here
{ $b = 6 } // nothing is printed here
{ $c = $a + $b } // nothing is printed here
{ print($c) } // "11" is printed in the mail.
Last edit: 8 years 6 months ago by Siem. Reason: forgot something
The topic has been locked.
More
8 years 6 months ago #135514 by coeneisma
Replied by coeneisma on topic using variables in admin mail notification
Maybe I don't understand the question correct, but you can use Expression Manager code in the admin mail notification, which can be used to display scores.
The following user(s) said Thank You: Siem
The topic has been locked.
  • Siem
  • Siem's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 6 months ago #135518 by Siem

coeneisma wrote: Maybe I don't understand the question correct, but you can use Expression Manager code in the admin mail notification, which can be used to display scores.


I can use the Expression Manager code there.
Basicly I want to know how to use variables in the Expression Manager (if that's possible). Should I define these variables first?
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
8 years 6 months ago #135520 by Mazi
If the variables are not defined within the survey, where does the data come from? If it is no dynamic data, why can't you hard code it within the text?

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The following user(s) said Thank You: Siem
The topic has been locked.
  • Siem
  • Siem's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 6 months ago #135523 by Siem

Mazi wrote: If the variables are not defined within the survey, where does the data come from? If it is no dynamic data, why can't you hard code it within the text?


I could hardcode it in the text, but the code is quite long. Certain long calculations are done multiple times within different formulas.
So in order to keep it sane, variables could be handy.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
8 years 6 months ago #135527 by Mazi
You can use variables by adding "equation" questions at your survey. Just enter the variable value at the question text and use the question code as variable name.
You can then use the Expression Manager for calculations like:
{(a.NAOK + b.NAOK) / c.NAOK}

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The following user(s) said Thank You: Siem
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 6 months ago #135537 by tpartner
Replied by tpartner on topic using variables in admin mail notification
In Expression manager, unlike JavaScript and other languages, you cannot simply declare and define variables. Variables are only question or sub-question answers, token attributes or a few other survey parameters so, as Mazi says, must be defined in the survey.

www.limesurvey.org/manual/Expression_Man...#Access_to_Variables

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Siem
The topic has been locked.
  • Siem
  • Siem's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 6 months ago #135539 by Siem

tpartner wrote: In Expression manager, unlike JavaScript and other languages, you cannot simply declare and define variables. Variables are only question or sub-question answers, token attributes or a few other survey parameters so, as Mazi says, must be defined in the survey.

www.limesurvey.org/manual/Expression_Man...#Access_to_Variables


Thanks that's clear. For now I will skip the variable part then and make my formula's longer.

There's only one last hurdle for me to make that work: how would you make the (simplified) examples below valid?
Code:
{ if ( countif(Q1=='A1',Q2=='A1',Q3=='A1',Q4=='A1') > 1, 'more than one' , 'not more than one') }
{ if ( ( countif(Q1=='A1',Q2=='A1',Q3=='A1',Q4=='A1') - 2 ) > 1, 'more than one' , 'not more than one') }
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 6 months ago - 8 years 6 months ago #135549 by tpartner
Replied by tpartner on topic using variables in admin mail notification
It seems to me that should be something like:

Code:
{if(sum(Q1=='A1',Q2=='A1',Q3=='A1',Q4=='A1') > 1, 'more than one' , 'not more than one')}
{if((sum(Q1=='A1',Q2=='A1',Q3=='A1',Q4=='A1') - 2) > 1, 'more than three' , 'not more than three')}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 6 months ago by tpartner.
The following user(s) said Thank You: Siem
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose