Have an idea?

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

Can I use this script to get preselect from previous loop question?

Can I use this script to get preselect from previous loop question?

<script>
[% Begin Unverified Perl
for (my $question = 19; $question <= 36; $question++) {
    for (my $item = 11; $item <= 22; $item++) {
        if (GETVALUE('B14Ax' . $question . '_' . $item)) {
            return 'SSI_SetSelect("DumB14ABC_4", true);';
        }
    }
}
return '';
End Unverified %]
</script>
asked Aug 13 by Saroeun Bronze (2,715 points)

1 Answer

0 votes
Try this:

<script>
[% Begin Unverified Perl
my $loopList = 'list1';

my $loopLength = LISTLENGTH($loopList);
for (my $i = 1; $i <= $loopLength; $i++) {
    for (my $question = 19; $question <= 36; $question++) {
        for (my $item = 11; $item <= 22; $item++) {
            if (GETVALUE('B14Ax' . $question . '_' . $item . '_' . LISTVALUE($loopList, $i))) {
                return 'SSI_SetSelect("DumB14ABC_4", true);';
            }
        }
    }
}
return '';
End Unverified %]
</script>


"list1" should be replaced with the name of the list used for looping.
answered Aug 13 by Zachary Platinum Sawtooth Software, Inc. (185,025 points)
preselect in a loop
...