Have an idea?

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

branching issue

I appear to have some issues with my branching script and had a few questions.  I assume I can have all questions on the same page (unlike with skip logic)?  Currently all questions show up and do not go away despite the selection in L1.  This is my script. Any help is much appreciated.  In another branching, I am getting it to work but only in the opposite way I want so I must be doing something incorrectly.
<script>
var GLOBAL_SAWTOOTH_[% QUESTIONNAME() %]_SETTINGS = {
    branchings: [
            {
                dependentQuestion: 'L2b',
                condition: function() {
                    return SSI_GetValue('L1')<>1;
                },
                selectMinimum: 1
            },
            {
                dependentQuestion: 'L3',
                condition: function() {
                    return SSI_GetValue('L1')==4||('L1')==5||('L1')==7||('L1')==8
                },
                  selectMinimum: 1
            },
            {
                dependentQuestion: 'L41',
                condition: function() {
                    return SSI_GetValue('L1')<>1
                },
                  selectMinimum: 1
            },
            {
                dependentQuestion: 'L42',
                condition: function() {
                    return SSI_GetValue('L1')==2||('L1')==3||('L1')==4
                },
                  selectMinimum: 1
            },
            {
                dependentQuestion: 'L43',
                condition: function() {
                    return SSI_GetValue('L1')==2
                },
                  selectMinimum: 1
            }
    ],
    errorMessageSettings: {
        missingAnswer: 'A response is required.',
        minimumChecks: 'The minimum number of checks is [MINIMUM].',
        minimumCharacters: 'The response must contain at least [MINIMUM] characters.'
    }
};
</script>
asked Jan 25 by sallen Bronze (905 points)

1 Answer

0 votes
 
Best answer
The information that I shared with our support team on the 21st regarding your Branching behavior was that you appeared to be using a recent version of Branching, but an older version of the Better Lighthouse Library.  This difference of versions is proving incompatible.

JavaScript does not recognize "<>" as an operator.  Try "!=" instead to test inequalities.

Your conditional scripts relating to L3 and L42 are not valid JavaScript syntax.  You need to write out the SSI_GetValue function call each time or, better yet, save the value to memory and then use that in your conditional:

condition: function() {
    var resp = SSI_GetValue('L1');
    return resp == 4 || resp == 5 || resp == 7 || resp == 8;
}
answered Jan 26 by Zachary Platinum Sawtooth Software, Inc. (164,025 points)
selected Jan 26 by sallen
Give it a spin.
It does not seem to work.  I tried just the two conditions but the dependent question does not appear when "2" is selected.
<script>
var GLOBAL_SAWTOOTH_[% QUESTIONNAME() %]_SETTINGS = {
    branchings: [
            {
                dependentQuestion: 'A04B',
                condition: function() {
                    return SSI_GetValue('A04A') == 1;
                }
            },
            {
                dependentQuestion: 'A31b',
                condition: function() {
                    return SSI_GetValue('A04A') == 1;
                }
            },
            {
                dependentQuestion: 'A33',
                condition: function() {
                    return SSI_GetValue('A04A') == 2 && SSI_GetValue('A32') == 2;
                }
            },
            {
                dependentQuestion: 'A35',
                condition: function() {
                    return SSI_GetValue('A04A') == 2 && SSI_GetValue('A34') == 2;
                }
            },
            {
                dependentQuestion: 'A11b',
                condition: function() {
                    return SSI_GetValue('A04A') == 2;
                }
            },
            {
                dependentQuestion: 'A36',
                condition: function() {
                    return SSI_GetValue('A04A') == 2;
                }
            }
    ],
    errorMessageSettings: {
        missingAnswer: 'A response is required.',
        minimumChecks: 'The minimum number of checks is [MINIMUM].',
        minimumCharacters: 'The response must contain at least [MINIMUM] characters.'
    }
};
</script>
Nothing in that snippet looks wrong to me.
Is it an issue that A04A and A32 are on different pages? A04A is on the page where the branching is and A32 is on a previous page.  No matter what I select in A32 and A34, A33 and A35 are not showing up now.
SSI_GetValue and other JavaScript are for getting values that exist on the current page.  Sawtooth Script is for getting values that exist on other pages.
...