Have an idea?

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

How to build constructed list based on Pass-In field?

I have a pass-in field which indicates the method to conduct the survey, like phone or online. I wanted to build a constructed list to display different options to respondents surveyed by different methods. For example, for the phone survey, I want to display option 1-5, but for the online survey, I only want to display option 1-4.

I firstly build a parent list named Q24List, then I wrote a the following unverified perl in the list instructions field of the constructed list

Begin Unverified Perl
{ADD("Q24List",1,4);}
if (method=="online")
{ADD("Q24List",5);}
End Unverified

But it does work. Can anyone help me to fix the problem?
asked Aug 17, 2015 by Angela (155 points)

1 Answer

+1 vote
 
Best answer
Angela, Perl is case sensitive so however you defined your fields / questions is relevant when writing your Perl script. Also, when using SSI Script functions in Perl, they must be defined as they are written in the Sawtooth Software help. Case sensitivity plays a large role with Perl.

I would suggest your "method" variable be defined as an integer type. It's easier to deal with numbers in logic. If you are stuck with text that's okay as we can still deal with it.

Note - If your "method" variable is to remain as type text, you will be using a different operator than "=" (e.g. "eq").

Here's an example of a constructed list that will guide you ...
Begin Unverified Perl 
  
 if (VALUE("method") eq "online")
  {  
   ADD("Q24List",1,4);
  }

 elsif (VALUE("method") eq "phone")
  {  
   ADD("Q24List",1,5);
  }

End Unverified

If you convert your "method" variable to an integer, your operators will switch from "eq" to "==". See below where method=1 (online) and method=2 (phone)...
Begin Unverified Perl 
  
 if (VALUE("method")==1)
  {  
   ADD("Q24List",1,4);
  }

 elsif (VALUE("method")==2)
  {  
   ADD("Q24List",1,5);
  }

End Unverified

Let me know how you go. Regards.
answered Aug 18, 2015 by Paul Moon Platinum (62,030 points)
selected Aug 18, 2015 by Angela
Where is "method" defined?
...