Have an idea?

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

How to use constructed lists in a series of questions

I know that I need constructed lists for Q4 and Q5.
I can get Q4 to work with: and if/remove function....
But I can't get Q5 to work if those options were removed.....


Q2.  Select question with two choices

Q4. Grid question with 12 rows and 6 columns: How frequently......?
[PROGRAMMER: If Q2 = 1, do NOT show 6, 7, 8, 9 or 12]

Columns:  Daily    Weekly        Monthly    Less than Monthly    Never    N/A
Rows: 1-12

Q5.  Grid Question with 5 columns.
Thinking of your selections in Q4, how important are they....

[PROGRAMMER: Pipe up to 3 selections from Q4 rated 1-3 (daily, weekly, monthly), or Rows 10-12 rated 1-4 (daily, weekly, monthly, less than monthly) least fill. Prioritize selections 10,11,12]
asked Nov 13 by Kayla (220 points)

1 Answer

0 votes
This can be done, but it'll take a bit of setup.

First, create a quota question.  It needs to have twelve cells with cell values 1 through 12.  Each cell can be set to always qualify with some large limit like 99999.  The question the quota should skip to if disqualified can be any question in the survey.  Now copy-and-paste this quota question so that you have three of them.

Place the three quota questions on some page after the terminate questions of your survey.  We don't want respondents to actually land on these questions while taking the survey.

Now you can create your constructed list.  Its parent list should be the list of twelve items.  Its instructions should be this:

Begin Unverified Perl
# Parameters
my $plist = 'list1';
my $gridQ = 'GridQ';
my @quotaQs = ('QuotaQ1', 'QuotaQ2', 'QuotaQ3');

# Run
my @contestants = ();
my $bestCompletes = 9999999;

for (my $item = 1; $item <= 9; $item++) {
    if (GETVALUE($gridQ . '_r' . $item) <= 3) {
        my $completes = getTotalQuotaCellCompletes($item);
        if ($completes < $bestCompletes) {
            @contestants = ($item);
            $bestCompletes = $completes;
        }
        elsif ($completes == $bestCompletes) {
            push(@contestants, $item);
        }
    }
}
for (my $item = 10; $item <= 12; $item++) {
    if (GETVALUE($gridQ . '_r' . $item) <= 4) {
        my $completes = getTotalQuotaCellCompletes($item);
        if ($completes < $bestCompletes) {
            @contestants = ($item);
            $bestCompletes = $completes;
        }
        elsif ($completes == $bestCompletes) {
            push(@contestants, $item);
        }
    }
}

my $added = 0;

for (my $item = 10; $item <= 12; $item++) {
    for (my $i = 0; $i < scalar @contestants; $i++) {
        if ($contestants[$i] == $item) {
            ADD($plist, $item);
            SETVALUE($quotaQs[$added], $item);
            splice(@contestants, $i, 1);
            $added++;
            last;
        }
    }
}

while ($added < 3 && scalar @contestants > 0) {
    my $index = RANDNUM(RESPNUM(), 0, scalar @contestants - 1);
    my $item = $contestants[$index];
    ADD($plist, $item);
    SETVALUE($quotaQs[$added], $item);
    splice(@contestants, $index, 1);
    $added++;
}

SORTBYVALUE();

sub getTotalQuotaCellCompletes {
    my ($item) = @_;
    my $completes = 0;
    foreach my $quotaQ (@quotaQs) {
        $completes += QUOTACELLCOMPLETES($quotaQ, $item);
    }
    return $completes;
}
End Unverified


Line 3 must be updated with the name of the parent list, line 4 must be updated with the name of the grid question, and line 5 must be updated with the names of the three quota questions.

Please test thoroughly.
answered Nov 13 by Zachary Platinum Sawtooth Software, Inc. (129,350 points)
Zachary- just to be clear- this con list is for  Q.....4 or 5?
I tried to make this the conlist for Q5 and it did not work....
Q5 always pipes in Q4 rows 10-12 whenever Q4 removes those 5 options (even though those options are not even displayed)
The instructions are meant for Q5; it sounded like you had Q4 worked out.  There may be an issue with how I handled those missing items.  Hopefully I'll have time to look at this one some more later today.
Zachary-

Thanks for your input!!

Whenever I couldn't get this to work, I came up with a work-around-
Which was forcing the grid questions that needed to be hidden to have a response of "6", then hiding them.

After that, my constructed list for Q5 worked-



<script>
if ("[%Q2%]"==1)
 {
  SSI_SetSelect("Q4_r6_6", true);
  $('#Q4_r6_row').hide();
$('[id^=Q4_r6_]').closest('.mobile_grid_card').hide();

}
</script>




<script>
if ("[%Q2%]"==1)
 {
  SSI_SetSelect("Q4_r7_6", true);
  $('#Q4_r7_row').hide();
$('[id^=Q4_r7_]').closest('.mobile_grid_card').hide();

}
</script>



<script>
if ("[%Q2%]"==1)
 {
  SSI_SetSelect("Q4_r8_6", true);
  $('#Q4_r8_row').hide();
$('[id^=Q4_r8_]').closest('.mobile_grid_card').hide();

}
</script>



<script>
if ("[%Q2%]"==1)
 {
  SSI_SetSelect("Q4_r9_6", true);
  $('#Q4_r9_row').hide();
$('[id^=Q4_r9_]').closest('.mobile_grid_card').hide();

}
</script>



<script>
if ("[%Q2%]"==1)
 {
  SSI_SetSelect("Q4_r12_6", true);
  $('#Q4_r12_row').hide();
$('[id^=Q4_r12_]').closest('.mobile_grid_card').hide();

}
</script>
...