Have an idea?

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

Error with Custom Jscript Verification + Constructed List

Hello all,
I am running some custom verification on a numeric grid question (Q11) vs. a numeric grid question on a prior page, Q10.
Q10 asks the respondent the number of visits they made to certain brands in the past 3 months. Q11 then asks them to assign those visits across 4 day parts (four rows in a grid) for each brand.
I'm attempting custom jscript verification to ensure that the sum of their 4 daypart answers is equal to the total # visits entered on Q10 on the prior page.
Each brand (row in Q10 and column in Q11) has its own verification. My script looks like this:
if ((SSI_GetValue("Q11_r1_c1") + SSI_GetValue("Q11_r2_c1") + SSI_GetValue("Q11_r3_c1") + SSI_GetValue("Q11_r4_c1")) != [%Q10_r1_c1%])

{
strErrorMessage = "Your total number of visits to BJ's Brewhouse should add up to the number of visits in the past three months that you indicated in the prior question: [%Q10_r1_c1%]. Please revise your answers.";
}


if ((SSI_GetValue("Q11_r1_c2") + SSI_GetValue("Q11_r2_c2") + SSI_GetValue("Q11_r3_c2") + SSI_GetValue("Q11_r4_c2")) != [%Q10_r2_c1%])

{
strErrorMessage = "Your total number of visits to Bonefish Grill should add up to the number of visits in the past three months that you indicated in the prior question: [%Q10_r2_c1%]. Please revise your answers.";
}

etc....
The problem is, the script is failing when run. I think the problem has to do with the fact that not all respondents see all brands (the brands they see are based on a Constructed list), so when the javascript runs for a brand they didn’t actually see in Q10 or Q11, it doesn't know what to do. Here's what it looks like in the debugger, where the [%Q10%] reference is just blank:
[code]
if ((SSI_GetValue("Q11_r1_c2") + SSI_GetValue("Q11_r2_c2") + SSI_GetValue("Q11_r3_c2") + SSI_GetValue("Q11_r4_c2")) !=

{
strErrorMessage = "Your total number of visits to Bonefish Grill should add up to the number of visits in the past three months that you indicated in the prior question: . Please revise your answers.";
}
[\code]

Is there a way to use the “Shown” function here? Any advice?
asked Feb 23, 2017 by cschlosser Bronze (1,005 points)

1 Answer

+1 vote
 
Best answer
Unverified Perl can come in handy in cases like this.  "Shown" could probably handle this, but I went with "ListHasParentMember" instead.  Here's my code for the first two restaurants:

var q10r1 = [% Begin Unverified Perl
    if (LISTHASPARENTMEMBER('ConstList', 1)) {
        return GETVALUE('Q10_r1_c1');
    }
    return 0;
    End Unverified %];

if (SSI_GetValue('Q11_r1_c1') + SSI_GetValue('Q11_r2_c1') + SSI_GetValue('Q11_r3_c1') + SSI_GetValue('Q11_r4_c1') != q10r1) {
    strErrorMessage = 'Error 1';
}

var q10r2 = [% Begin Unverified Perl
    if (LISTHASPARENTMEMBER('ConstList', 2)) {
        return GETVALUE('Q10_r2_c1');
    }
    return 0;
    End Unverified %];

if (SSI_GetValue('Q11_r1_c2') + SSI_GetValue('Q11_r2_c2') + SSI_GetValue('Q11_r3_c2') + SSI_GetValue('Q11_r4_c2') != q10r2) {
    strErrorMessage = 'Error 2';
}


"ConstList" should be replaced with the name of the constructed list.

That code will use GETVALUE when there is a value to get and simply return 0 when there is not a value to get.  Hopefully this will get you going.
answered Feb 23, 2017 by Zachary Platinum Sawtooth Software, Inc. (76,175 points)
selected Feb 23, 2017 by cschlosser
That worked beautifully, thank you!!
...