Piping From a Checkbox Into a Grid Question

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 scenario, we are going to set up a custom script to filter the grid rows displayed in a target question based on any corresponding options selected in the source checkbox question. Normally, it would be fine to use standard piping, but here the source question contains options for both Sega and Nintendo classic video games, but in the target question, we only want to ask about Nintendo video games which respondents have played.

For this to work the target question must be setup with the Nintendo classic games row titles from the source question as grid rows, with automatic piping turned off.

Note: We are using this question to custom pipe from a checkbox question to a checkbox grid question, however, because all grid questions are set-up with each row given a separate question id we can use it to custom pipe from a checkbox question to any grid question (i.e. radio button, textbox, dropdown menu grid).

Check out the 3rd and 4th page of this example survey!

OR

Add this survey to your account!

Estimated implementation and testing time: 5-10 minutes

This script uses the following custom scripting functions:

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

The Script

The script below requires us to plug in the id of the source checkbox question, the id of the target grid question and the page id or the page to jump to in case there are no rows left to display in the target question due to the filtering.

//checkbox questions to grid rows filtering

%%source_id = 18; //question id of checkbox q
%%target_id = 34; //question id of grid
%%next_page_id = 3; //page id of the next page - used to jump to in case there are no rows to show in the grid

%%source_values = sgapiGetValue(%%source_id); //array of source options checked, sku => reporting value
%%target_question_titles = sgapiGetTableQuestionTitles(%%target_id); //array of grid question row titles, question id => row title

%%hidden_qids = 0;
foreach(%%target_question_titles as %%id => %%title){

   if(!(sgapiIn_Array(%%title,%%source_values))){
      
      sgapiHideQuestion(%%id, true);
      %%hidden_qids += 1;
   } 

}

//if there are no options left to show, skip to the next page  
if(sgapiCount(%%target_question_titles) == %%hidden_qids){

   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_id - This variable will indicate the question ID of the source Checkbox 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 question that correspond to the table rows titles of the target table question.

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!