Have an idea?

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

Programming questions

Question - 1 :
Need programmed two single response questions Q1 and Q2 and  auto code Q2=1 if Q1=1.  Is it possible to get script.

Question - 2:
We have 4 options in a single response question and need to hide last option if any row selected in column A in grid question.Is it possible to get script.

Question - 3:
Need to re-code grid question into new hidden question. Based on the below details       
0 to 6 - code 1   
7 or 8 - code 2   
9 or 10 - code 3
Is it possible to get script.
asked Oct 17, 2018 by WasidKhan (120 points)
Are Q1 and Q2 on the same page?

Is the select question and grid question on the same page?  What direction and input type is the grid question?

When exporting data from Lighthouse Studio, there's an option to recode responses.  Is this sufficient for your recoding needs?
1) No,  Q1 and Q2 are not on same page.

2) No, Select and grid questions are on different page.  It is Row grid question.  For example, if we select "column A" for any row then option 4 at select question should not be shown.  

3) We have an requirement to show in survey itself.  Could you please help on it.
If anyone can help me on above request that would very helpful for me.

1 Answer

0 votes
Q1 needs a skip that skips past Q2.  The skip should have this logic:

Begin Unverified Perl
if (GETVALUE('Q1') == 1) {
    SETVALUE('Q2', 1);
    return 1;
}
return 0;
End Unverified


I can't help with the others without knowing the input type of those grid questions.  Radio buttons?  Checkboxes?
answered Oct 17, 2018 by Zachary Platinum Sawtooth Software, Inc. (100,575 points)
We have a row grid question as Q3.
Q3 has 12 rows and 5 columns.  And another Question Q10 is single select question and it has 4 options.
We  need to hide option 4 of Q10 if column 4 is selected in Q3 for at least one row.

Could you please help on it.
Your second and third questions in the original post both refer to grid questions.  Knowing the direction (rows vs. columns) and number of rows and columns of those grids is nice, but I also need to know what input type those grid questions are using.  Which of these input types are your two grid questions using?

* Radio buttons / single response
* Checkboxes / multiresponse
* Comboboxes / dropdowns
* Numeric
* Textbox (single line)
* Textbox (multiple lines) / textarea
* Constant sum
* Ranking
Thanks for looking into this,  both grid questions are Radio buttons / single response.
For your second question, place this script into your select question's footer:

<script>
if ([% Begin Unverified Perl
        # Parameters
        my $gridQ = 'Q1';
        my $gridQRowList = 'Q1RowList';
        
        # Run
        my $listLength = LISTLENGTH($gridQRowList);
        for (my $i = 1; $i <= $listLength; $i++) {
            if (GETVALUE($gridQ . '_r' . $i) == 1) {
                return 1;
            }
        }
        return 0;
    End Unverified %]) {
    $('#[% QuestionName() %]_4').closest('.response_row').hide();
}
</script>


Lines 4 and 5 need to be updated with the name of your grid question and the name of your grid question's row list, respectively.

For your final question, add a pass-in field for each row of your grid question.  Their names should follow a simple pattern like pif1, pif2, pif3...  Then place this script on a page after the grid question:

[% Begin Unverified Perl
# Parameters
my $gridQ = 'Q1';
my $passInFieldBaseName = 'pif';
my $numberOfFields = 4;

# Run
for (my $i = 1; $i <= $numberOfFields; $i++) {
    my $in = GETVALUE($gridQ . '_r' . $i);
    my $out;
    if ($in <= 6) {
        $out = 1;
    }
    elsif ($in <= 8) {
        $out = 2;
    }
    else {
        $out = 3;
    }
    SETVALUE($passInFieldBaseName . $i, $out);
}
End Unverified %]


Line 3 should be updated with the name of the grid question, line 4 with the base name used in the pass-in fields, and line 5 with the number of pass-in fields.  You can also toggle what grid response values turn into what other values by changing the numbers on lines 11 through 19.
Thank you very much. It is really helpful for me.
...