Have an idea?

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

Pipe in / Get the value for a randomly assigned member from a numeric question

I have a numeric grid question “Q2” where respondents are required to enter a value for 10 brands they’re currently using.
For any value Q2_c1>0 then I construct a list called “BrandSelect1” that randomly assigns 1 brand that the respondent is currently using based on a Parent list called “BrandParent”.

In a follow up question Q3, I want to bring in / pipe in the value they entered in Q2 but specific to the randomly assigned “BrandSelect1” list.
So if brand assigned was member # 3 in the “BrandParent” I want to display the value in Q2_r3_c1, if the brand assigned was member #1 in the “BrandParent” then I want to display the value in Q2_r1_c1 and so on.

I figured I’ll need to create another constructed list that will store the value of Q2 based on the brand assigned, and then in Q3 I’ll pipe in the value by using [%ListLabel(QtyBrandSelect1,1)%]

And so the new constructed list called QtyBrandSelect1 I used the following perl (just for member #1 for illustrative purposes, but I have to repeat it 10 times) ...
but it doesn’t work!

Begin Unverified Perl
if(VALUE("BrandSelect1") == 1)
return .VALUE("Q2_r1_c1").;
End Unverified

I also used

Begin Unverified Perl
ADD ("Q2_r1_c1").;
End Unverified

And so I have a few of questions:
1)    Is my assumption to use a constructed list as above, correct? Is there an easier way to do this?
2)    if indeed I need a constructed list, what is missing/wrong in the new QtyBrandSelect1 constructed list?
3)    And is it correct how I pipe in the value in Q3 as [%ListLabel(QtyBrandSelect1,1)%]?

Thank you in advance to anyone who can steer me in the right direction!
asked Aug 25, 2016 by Elena Catoiu
Few quick thoughts concerning your Perl:

1.  You have two dot operators around the "VALUE" call and one after the "ADD" call.  I don't believe any of those should be there.

2.  "VALUE" cannot accept lists for parameters.  This function requires a question for a parameter.

3.  "ADD" cannot accept questions for parameters.  This function requires a list for a parameter (and then one or two optional numbers).
Thank you Zachary, that makes sense now!

1 Answer

+1 vote
Zachary has pointed out a few Perl issues you have which are spot on.

When I have these problems, I use something like this ...
[%Begin Unverified Perl 

 my $BrandValue=0;

 return $BrandValue;
End Unverified%]

This will return the value of the first brand from the BrandSelect1 list. I assume this list populates all brands>0 from Q2 and randomises them.

Pop this Perl script into the question where you want it displayed.

Just tested it and it works nicely.
answered Aug 26, 2016 by Paul Moon Platinum (55,975 points)
Paul, this is such an elegant solution to my problem. I tested it and it works beautifully! Thank you!!
Good one. Glad you got it working.