Have an idea?

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

add answersoptions based on loop

Thanks a lot, this works fine!

A related question: we decided we want to add some items to the answersoptions in Q2-Q8 based on the specific answer in Q1 that is looped. Is it possible to add this into the loop? So that every time it's looped, the answersoptions in Q2-Q8 are slightly different?
asked Nov 11, 2021 by Jeroen

1 Answer

0 votes
When a constructed list first appears inside a loop, the survey will create multiple instances of the constructed list, one for each loop iteration.  So we just need to define the constructed list instructions to account for the loop value.  If the rule were something as simple as "on loop value X, add item X," then the instructions would be like this:

Add(list1, LoopValue())

If your rule were something more complex, we might need to break out unverified Perl and make the instructions something like this:

Begin Unverified Perl
my $loopValue = LOOPVALUE();
if ($loopValue == 1) {
    ADD('list1', 1);
    ADD('list1', 2);
elsif ($loopValue == 2) {
    ADD('list1', 3);
elsif ($loopValue == 3) {
    ADD('list1', 4);
    ADD('list1', 5);
End Unverified

Hopefully those examples can get you going, but if not I could help you write the exact instructions you need if you can detail all the rules you need for what items to show when.
answered Nov 11, 2021 by Zachary Platinum Sawtooth Software, Inc. (205,575 points)