Piping: Checkbox Grid to Radio Button Grid

Important Update to Custom Scripting

SurveyGizmo's CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!

Legacy Custom Scripting Language Deprecation Plans 

  1. New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
  2. As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
  3. In the long term, Legacy Custom Scripting Actions will be switched to read-only. The exact date on this is to be determined; we will send notifications well ahead of time.

In this example we are going to only show the rows in the target radio button grid questions for which any of a specified set of column answers were checked in the source grid.

For this to work, the target grid question must be setup with row titles as from the source checkbox grid question.

Note: This script can work with conditional piping from a Checkbox Grid question to any other Grid question, as all Grid questions in SurveyGizmo have the same structure, with each row corresponding to a separate question id.

Example survey (4th to 5th page): http://www.surveygizmo.com/s3/2158470/Custom-Piping-Filtering

OR

Want to download this survey to your account so you can play with it? Just click here.

Estimated implementation and testing time: 5-10 minutes

This script uses the following custom scripting functions:

  • sgapiArrayFlip
  • sgapiGetTableQuestionTitles
  • sgapiGetValue
  • sgapiHideQuestion
  • sgapiIn_Array
  • sgapiCount
  • sgapiJumpToPage

The Script

The script below requires the for us to plugin the question id of the source checkbox grid question, the question id of the target radio button grid question, the id of the next page to jump to (should there be nothing to display on the page with the target question), and an array with the comma-separated, single quote marks enclosed names for each of the options from the checkbox grid columns you would like to be in the qualifying answers to have that row displayed in the target radio button grid question.

%%source_id = 34;
%%target_id = 3;
%%next_page_id = 6;
%%target_options = array('I have played this game frequently','I used to own this game','I still own this game'); //this is the array of options which qualify that row for being shown in the subsequent grid if one of them is ticked

%%checkboxtable = sgapiArray_Flip(sgapiGetTableQuestionTitles(%%source_id)); //row title => id
%%radiotable = sgapiArray_Flip(sgapiGetTableQuestionTitles(%%target_id)); //row title => id



%%hidden_rows = 0;
foreach(%%checkboxtable as %%title => %%id) { //loop through the checkbox grid question rows

   %%row_values = sgapiGetValue(%%id); //get the values, each row is like a separate checkbox question
   sgapiHideQuestion(%%radiotable["%%title"], true); //initially hide the corresponding row from the radio button grid
   %%hidden = true;
   foreach(%%row_values as %%value) { // loop through the checkbox question row

      if(sgapiIn_Array(%%value, %%target_options)){ // if the value checked is in the target options array, then unhide the corresponding row in the radio grid

         sgapiHideQuestion(%%radiotable["%%title"], false); //initially hide the corresponding row from the radio button grid
         %%hidden = false;

      }

   }
   
   // here we increment the counter for hidden rows in the radiobutton grid
   if(%%hidden === true) {

      %%hidden_rows += 1;

   }

}

if(%%hidden_rows == sgapiCount(%%radiotable)) {

   sgapiJumpToPage(%%next_page_id);

}

In the script above you will need to customize variables highlighted in yellow in order to make the script work the way you'd like.

Required Customizations

%%source_id1 - This variable will indicate the question ID of the source Checkbox Grid question.

%%target_id - This variable will indicate the question ID of the target grid question.

%%next_page_id - The page to jump to if no options are selected in the Checkbox Grid question such that the corresponding rows are displayed in the target grid question (and therefore this question has no rows so the page should be skipped).

%%target_options - The array of options ticked per row which you wish to qualify that row for being displayed in the target grid question, formatted as you see in the script, encased in single or double quotes and comma separated with no comma after the last one.

Scripting and Other Custom Solutions

We’re always happy to help you debug any documented script that is used as is. That said, we do not have the resources to write scripts on demand or to debug a customized script.

If you have customization ideas that you haven't figured out how to tackle, we're happy to be a sounding board for SurveyGizmo features and functionality ideas that might meet your customization. Beyond this, you might want to consult with someone on our Programming Services Team; these folks might have the scripting chops to help you to achieve what you are looking for!