Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

what is the error in the below syntax, this creates sawtooth error #132

Begin Unverified Perl

 if (GETVALUE("A4") < 15) {
    SETVALUE("A4Grp", 1);
   
}
else if (GETVALUE("A4")>=15 && GETVALUE("A4")< 19) {
    SETVALUE("A4Grp", 2);
}

End Unverified


I have written this code in pre-skip logic of A4Grp, where A4Grp is select type question contains around 8 options.

If I use only the first if condition it didnt create any error but it would set any values in A4Grp, means that SetValue function doesnt work properly.
related to an answer for: How to add multiple if conditions?
asked Jun 17 by raaamuz (360 points)

1 Answer

0 votes
With Unverified Perl you need to use elsif for your second statement, not 'else if'.  It's just one word with no spaces and no 'e'.  That should solve your problem. See below.

Begin Unverified Perl
 
 if (GETVALUE("A4") < 15) {
    SETVALUE("A4Grp", 1);
    
}
elsif (GETVALUE("A4")>=15 && GETVALUE("A4")< 19) {
    SETVALUE("A4Grp", 2);
}
 
End Unverified
answered Jun 17 by Jay Rutherford Gold (32,940 points)
Thanks for the additional detail Zach.  I see that could be the problem, if that is what he has done.  If the question A4Grp was set up instead of a Pass-In Variable, I would think it would be a single select.  If so, then they may want to pre-skip A4Grp and put the perl code I provided in a question after A4Grp that all would see.  I commonly do this when I ask an open numeric question but they also want them grouped categorically.  Either set up a question that is skipped or set up a Pass-In variable instead.  Both work well.
This works well only when we write this syntax on A4Grp, but A4Grp is a hidden question so I was trying to logic when it exit from question A4, do you have any other alternate solution?
If A4Grp is a hidden question and a single select then the script I provided will work as long as you place it on another question after A4.  Then it will store the value for A4Grp as you want.
Currently I placed A4Grp next to A4, do you want me to move A4Grp one question ahead? since it is a hidden question I am fine with keeping A4Grp anywhere but I just want to clearly understand your context, please confirm
The key is to put the script on a page AFTER A4 as it is calling upon the submitted responses to A4.  As long as you do that, it will set the responses for A4Grp using that script.
...