Have an idea?

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

Error message comparing 2 values in different questions

I am trying to write a custom error message that needs to refer to 2 different questions that are part of loops.  Respondents identify which brands of products they use early in the survey, and then this constructed brand list drives loop blocks of questions throughout the survey from that point on.  
Respondents then also identify what types of Representatives they see from those brands (Representatives2yrs) and there are 3 levels.  Only 2 of those representative types are relevant to question (RepPercCases), and the second one is not shown.  
I want to check if they selected Representative type 1 or 3 in (Representatives2yrs), and if not, display an error message in (RepPercCases) if they enter a value > 0 in (RepPercCases).  Here is the code I am trying to use in Advanced tab ("after" submitting), but it doesn't work and gets stuck:

if (SSI_GetValue ("Representatives2yrs_1.1") == 0 && SSI_LoopValue() == 1 && [% RepPercCases_r1.1 %] > 0)
{
strErrorMessage = "You entered a value where we were not expecting one based on your previous question responses.  Please verify you answers.";
}

Any suggestions?  I am also not sure if it needs to refer to the loop iteration/values or not.

Any help would be appreciated.
asked Jan 22 by FMetzger (140 points)
I may not totally understand how you have your study structured, but my initial concern would be that your code will not work is RepPercCases_r1.1 has no value.  Sawtooth Script returns blank in that case, which would produce invalid JavaScript like this:

if (SSI_GetValue ("Representatives2yrs_1.1") == 0 && SSI_LoopValue() == 1 &&  > 0) 


If this is a problem that you are or may experience, you'll want to surround the Sawtooth Script call with something that will give us valid JS whether the response is blank or not.  Quotation marks could do this, but I usually only use those when the response is text (e.g., open-end).  When it is expected to be a number, I prefer to use JavaScript's Number function.  "Number(123)" returns 123, while "Number()" is still valid and returns 0.

if (SSI_GetValue ("Representatives2yrs_1.1") == 0 && SSI_LoopValue() == 1 && Number([% RepPercCases_r1.1 %]) > 0) 
I could see one more issue in this code i.e. I think we can get loop value using only
[% LoopValue() %] 
function as I could not see any SSI defined function named SSI_LoopValue()

Your solution to the original question

Please only use this to answer the original question. Otherwise please use comments.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

To avoid this verification in future, please log in or register.
...