Have an idea?

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

Set range dynamically


I'd like to set the min/max values of consecutive numeric questions dynamically. The questions are on separate pages.

Question order: A, B, C, D
The logic is: C > B > A > D

Range settings (min, max):
A: 0, 1 000 000
B: [% A + 1 %], 1 000 000
C: [% B + 1 %], 1 000 000
D: 0, [% A - 1 %]

Now the tricky part is that each question has a "Don't Know" option. In case the don't know option is chosen, I want to set the next larger/lower value as the limit.

For example: If a respondent says "Don't know" for B but enters a value for A, I want to set the lower limit for C to [% A + 1 %] instead of [% B + 1 %]
--> max( [% A + 1 %], [% B + 1 %]).

In other words, how can I get multiple previous numeric answers into an array and return the maximum or minimum?
asked Mar 1 by Kathrin (255 points)

1 Answer

+1 vote
You can use some perl script and set the values conditionally based on previous response.  So in my example below I'm setting the value to 1000 based on q2 and if it doesn't meet that I'm setting it to the value of another question.  Hope this helps point you in the right direction.

[% Begin Unverified Perl
{return 1000}
else {return VALUE("Q1E");}
End Unverified %]
answered Mar 1 by Jay Rutherford Gold (41,660 points)
Thank you Jay, this helped fixing my problem:

[%Begin Unverified Perl
if((VALUE("BKA_1")==1) && (VALUE("AKA_1")==1)){return 0;}
if((VALUE("BKA_1")==1) && (VALUE("AKA_1")==0)){return VALUE("A") + 1;}
else {return VALUE("B") + 1;}
End Unverified %],

AKA_1 and BKA_1 being the NotApplicable-Option for A and B, respectively.

I'd still be interested if there is a way to gather the answers from multiple questions and return the maximum value. How can I express the following in correct perl script?:

 max( [% A  %], [% B  %])