Have an idea?

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

Dynamically reduced list in a loop

Hi everybody,
My aim is sequential choices of brands, each choice on a separate page (to be completed with some additional questions). In SSI7 I have to create as many lists as there are brands less one. I hoped I could simplify this in SSI8 using a loop. So far I have not been successful in creating a diminishing list of brands by removing those that have been selected in previous choices.
Say the parent list of 5 brands is BrandsPList, its randomized version is BrandsRandCList and the actual list a respondent should choose from is BrandsSelCList. The loop is over the parent list of brands so that the order of the choices is known (rather than randomized). The radio select question used as the loop body is SctSelect. I hoped this code would generate the sequentially reduced list BrandsSelCList:

Begin Unverified Perl
    ADD ("BrandsRandCList");
    for my $i (1..5) {
        RIC("SctSelect.".$i)
    }
End Unverified

However, the list is not reduced and all brands are shown in all select questions which makes the whole construct useless. Can anybody suggest a working solution?

Luděk Brož, g82 s.r.o.
asked Dec 6, 2012 by anonymous
retagged Dec 6, 2012 by Walter Williams
Could you confirm that what you want to do is something like this:
Q1: single select, 5 brands, choose one
Q2: single select, 4 brands (remove choice from Q1)
Q3: single select, 3 brands (remove choice from Q1)
and so forth?
Hi Brian,
Precisely that. The goal is to obtain ranking.
Luděk
Unfortunately it looks like you will have to stick with your approach of multiple lists.  As Paul mentions in his answer, constructed lists are evaluated the first time that they are called in the survey, so adding scripts and referencing the list again does not update it.  I'll see if anyone has an idea for any hack-ish ways of doing it, and will add another comment if anyone has any ideas internally.
Brian,
Thank you for the answer. Multiple lists would be of no problem, the multiple questions to be declared one by one are. Clients often ask to change the question wording back and forth.  
But back to loops. I am not quite sure what the fields BrandsRandCList.1, ..., BrandsRandCList.5 (not used in the question in the loop body) and BrandsSelCList.1, ..., BrandsSelCList.5 (used in the question) in table _clists (and later in the data file) are good for if all the 10 values are identical for a respondent and cannot be influenced programmatically. The lists corresponding to these fields cannot be built at the design time since constructed list names do not accept dot in their names.

Luděk Brož, g82 s.r.o.

2 Answers

+1 vote
I believe the 1st time around, the constructed list is evaluated and written to the data file and from that point on, when you call upon that constructed list again, it is not re-evaluated, it is used based upon the result when it was 1st written to the data file.

Is it possible for this to be confirmed by Sawtooth please?

If I am correct, this would require you to construct a number of lists (less 1) as you mentioned.
answered Dec 7, 2012 by Paul Moon Platinum (98,670 points)
Hi Paul,

I am afraid your idea would not work. SSI generates a new list for each pass in a loop internally, and writes the list in the _clists table in the database only after the question is answered. Therefore changing data in _clists table would have no effect.

By the way, replacing the "for () {}" block in the Perl code by a simple command 'RIC("SctSelect");', i.e.  with no explicit loop indices, leads to the same result. It is strange SSI does not protest against non-existent question "SctSelect" despite all the actual question names have dot indices.

Luděk
+1 vote
I believe your problem is that you are building all the constructed lists everytime for each question.  You shouldn't do that because once a constructed list is made then it is not remade again.

For example:  your code
for my $i (1..5) {
        RIC("SctSelect.".$i)
    }

says remove if chosen for SctSelect.1, SctSelect.2, SctSelect.3, SctSelect.4, SctSelect.5 everytime.  Well, the first time this runs, none of them have been made yet so it builds all of those lists right then and you are stuck with all of them containing everything.

This should work as you would expect.

What you want is to access the questions that have answers and nothing more so the code should look like this
Begin Unverified Perl
    ADD ("BrandsRandCList");
    my $Length = LOOPITERATION();
    for (my $i = 1; $i < $Length; $i++)
    {
        RIC("SctSelect.".$i) 
    }
End Unverified

This will cause the first time to never run any RIC function because nothing has been answered yet.  When the second question is hit, then it will call RIC once for .1.  On the third question it will run 2 times for .1 and .2.  And so on up to the end of the loop.
answered Dec 11, 2012 by Mike Lodder Gold (22,975 points)
Mike,
I am sorry to say neither this construct got it working. The array of the lists is probably built at the time of the first loop pass. I could be wrong but, to stay with the philosophy of SSI, I would expect something like a check box to activate "Refresh inside-loop lists at each pass" in the Loops configuration table.

Luděk Brož, g82 s.r.o.
...