- Posts: 55
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
using variables in admin mail notification
- Siem
- Topic Author
- Offline
- Senior Member
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?
{ $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.
- coeneisma
- Offline
- Senior Member
- Posts: 74
- Thank you received: 26
- Siem
- Topic Author
- Offline
- Senior Member
- Posts: 55
- Thank you received: 1
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?
- Mazi
- Offline
- Official LimeSurvey Partner
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
- Siem
- Topic Author
- Offline
- Senior Member
- Posts: 55
- Thank you received: 1
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.
- Mazi
- Offline
- Official LimeSurvey Partner
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
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10611
- Thank you received: 3691
manual.limesurvey.org/Expression_Manager#Access_to_Variables
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
- Siem
- Topic Author
- Offline
- Senior Member
- Posts: 55
- Thank you received: 1
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.
manual.limesurvey.org/Expression_Manager#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?
{ 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') }
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10611
- Thank you received: 3691
{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.