Have an idea?

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

Sawtooth Error # 269 While Trying to set values

This may be complicated so I am going to attempt to explain as best as I can.  There are three relevant questions.

Outside the loop
Q1: Which days of the week do you commute to work [it is a multiple select grid with the columns representing each day.]
 --Whatever days they select feeds into the loopList

Loop begins
Q2: what were your commute modes for day 1 (multiple select checkbox)
Q3: was your commute mode for day 2 the same as day 1?
 --If they answer 'yes' to this the next loop is skipped.

So, for example say I commute Mon, Tue, Wed.
-- for Q2 Monday I say I drive alone (loop1
-- I then say "yes" for Q3 indicating I also drive alone on Tuesday. so I am not asked Q2 for Tuesday (loop 2).
-- I then say "yes" for Q3 indicating I also drive alone on Wednesday. so I am not asked Q2 for Wednesday (loop 3).
 
The end goal is to create a variable showing what percent of commute days is spent doing a specific commute mode (e.g. driving alone).

Here is where the code comes in.  I have created a quick SawtoothScript run to get the number of days. I got this working and all seems well.
[% SetValue(numberOfDays,(Q1_r1_c1 + Q1_r1_c2 + Q1_r1_c3 + Q1_r1_c4 + Q1_r1_c5 + Q1_r1_c6 + Q1_r1_c7)) %]


The second bit that I have been able to SORT OF get to work is the number of days doing a specific mode.
[% SetValue(countMode,(Q2_19.1 + Q2_19.2 + Q2_19.3 + Q2_19.4 + Q2_19.5 + Q2_19.6 + Q2_19.7) ) %]


This works in that it successfully counts the number of times the variable is checked, BUT because loop2 and loop3 are skipped the value of countMode is 1 when it should really be 3.  I am now trying to write a little script in perl that essentially says:
"If Q3 = yes, then populate the next loop instance of Q2 with the previous instance of Q2"

My non-working attempt is here:
    if    (GETVALUE("Q3.2") == 2) {
        SETVALUE("Q3.3",(GETVALUE("Q3.2")));
}


I get Sawtooth Error 269 when I try to run that code.  

Update: Since initially starting this thread, I have completely commented out all code and still get the Error 269.  However, I can create a new text type question and start over. When I do this I can get the first two code sets to work (numberOfDays and countMode), but when I attempt the Perl I get the Error 269. I then comment out the perl and still get the 269.  So I comment out everything and still get 269.  Then create a new text type question and repeat.
asked Sep 4, 2021 by Nwiggin Bronze (1,785 points)
269 means a problem occurred running SetValue.  If you look in your admin module, there may be more info about what went wrong.

At a glance, does your unverified Perl need to be using "Q2" instead of "Q3" in two of those spots?
Zach, I'm not sure if you get pinged if I mark something as an answer, but I figured it out.  But it uses some rather inefficient code because Q2 is a multiple select.
SETVALUE ("Q2_1.2",(GETVALUE("Q2_1.1");
SETVALUE ("Q2_2.2",(GETVALUE("Q2_2.1");
SETVALUE ("Q2_3.2",(GETVALUE("Q2_3.1");
SETVALUE ("Q2_4.2",(GETVALUE("Q2_4.1");
and so on.


Is there a more efficient way of writing this?
It sounds like you're looking to use a Perl loop, right?

for (my $i = 1; $i <= 23; $i++) {
    SETVALUE('Q2_' . $i . '.2', GETVALUE('Q2_' . $i . '.1'));
}

1 Answer

0 votes
I spent most of the weekend toying around with this because it was confusing the heck out of me, but I figured it out.

There were two issues. One was me mis-labeling the variables. Q3 was part of the loop but I had set skip logic to ALWAYS skip Q3.1.  Meaning that the first Q3 the respondent would actually see was Q3.2 (is your commute on Monday the same as it was on Sunday).

The bigger issue was that Q2 was a multiple select in my SETVALUE code I was trying to set Q2.2 to the same value as Q2.1.  However, no data is written to Q2.2.  I tried doing the same basic code as above but changed it to read
SETVALUE ("Q2_1.2",(GETVALUE("Q2_1.1");

and that works.

But it leaves me with a further question...Q2 has 23 possible responses.  And the loop can run up to 7 times.  So I would need to write some really inefficient code.
SETVALUE ("Q2_1.2",(GETVALUE("Q2_1.1");
SETVALUE ("Q2_2.2",(GETVALUE("Q2_2.1");
SETVALUE ("Q2_3.2",(GETVALUE("Q2_3.1");
SETVALUE ("Q2_4.2",(GETVALUE("Q2_4.1");
and so on.


Is there a more efficient way of writing this?
answered Sep 7, 2021 by Nwiggin Bronze (1,785 points)
...