Have an idea?

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

Assign a value to a string variable

Hi guys,

I have a multiple response question (Q1) with 2 possibilities: A, B.

I have created a pass-in string variable (var1).

What I want to do:
If Q1_1=1, then var1="textA"
If Q1_2=1, then var1="textB"
(ignore the option where both are selected, that's not my problem for now)

What I've done:
I put this into the Footter of Q1
[% Begin Unverified Perl
End Unverified %]

To check if this was correct, I tried to print it into the footer of the survey
[% Begin Unverified Perl
return VALUE("var1");
End Unverified %]

But something is wrong... when I do the SETVALUE without the if, the text is assigned to the variable and printed. But when I use the if, nothing is displayed...

One more thing: after solve this, can I use the var1 to do skip logic?
Like: var1 = "textA", skip to Q123

Thanks again!

asked Feb 26, 2014 by Bruno Marques (315 points)
edited Apr 9, 2014 by Bruno Marques

1 Answer

+1 vote
Your Perl script looks correct.

One query I do have is setting the value of var1 to a text value? I haven't used it for that before, only for integer values to be honest.

Should the code be SETVALUE("var1",'textB'); or SETVALUE("var1","textB"); - does single quotes work?

You can use var1 in skips as you suggested. That is the correct syntax.

Regarding where you have placed your Perl script - which footer have you stored it in? You need Q1 answered before placing it there so best to pop it in a page after Q1.
answered Feb 26, 2014 by Paul Moon Platinum (70,065 points)
Thanks Paul Moon,

the problem was the positioning of the Perl Script, I changed it to the next question header and it works well.

Thanks again :)

Thought so based on your information you provided which explains why the conditional script wasn't working.