Have an idea?

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

Creating a list from a passed-in array

Hello,

I was hoping to find some help with a question I have about passing in an array and then turning this array into a constructed list within Lighthouse. In my example we have a list of 38 brands, but only want to show respondents brands that they would ever consider buying. We get this info from outside of Lighthouse and will pass this in as a text variable (as an array). So I was hoping to get code that would allow me to take this array and create a constructed list from the full brand list.

e.g. Respondent A has array passed in as [1,4,5,10,12,14] so instead of showing all of brands 1-38, they would only be shown those 6 products in our Lighthouse study.

 I believe I will need to use perl to achieve this, but am admittedly fairly beginnerish with perl syntax.

Thanks in advance for any help with this question!
asked Nov 6, 2019 by thansen (155 points)

1 Answer

+3 votes
 
Best answer
These constructed list instructions should suit your needs:

Begin Unverified Perl
# Parameters
my $plist = 'list1';
my $passInField = 'pif';

# Run
my $passIn = GETVALUE($passInField);
$passIn =~ s/[^0-9,]//g;
my @split = split(',', $passIn);
foreach my $item (@split) {
    ADD($plist, $item);
}
End Unverified


"list1" and "pif" must be replaced with the name of the parent list and the name of the pass-in field, respectively.
answered Nov 6, 2019 by Zachary Platinum Sawtooth Software, Inc. (147,925 points)
selected Nov 6, 2019 by thansen
Amazing! Thanks so much Zachary!!
...