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
- New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
- 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.
- 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.
As piping into answer options is not available for Textbox List questions, this script will query the answers from a source Checkbox question and filter the option list in a target Textbox List question accordingly. For this to work, the option titles of the Checkbox question must correspond exactly to the option labels of the Textbox List question. If no options are selected in the source question, the script jumps to a specified survey page (the next page in this case).
Check it out in an example survey!
OR
Add this surveyto your account!
Estimated implementation and testing time: 5-10 minutes
This script uses the following question types or actions:
- sgapiGetQuestionOptions
- sgapiGetValue
- sgapiIn_Array
- sgapiRemoveOption
- sgapiCount
- sgapiJumpToPage
The Script
This script will query the answers from a source Checkbox question and filter the option list in a target Textbox List question accordingly.
//filter a textbox list of labels by a source checkbox question //manual option filtering based on source question %%source_id = 2; // checkbox qid %%target_id = 3; //textbox list qid %%next_pageid = 2; // pageid of the next page to jump to if there are no options ticked in source_q //get t list of options for target q %%tgt_opts = sgapiGetQuestionOptions(%%target_id); %%source_labels = sgapiGetQuestionOptions(%%source_id); %%source_rvalues = sgapiGetValue(%%source_id); //construct a usable array of option_sku => checkbox label for selected checkbox options foreach(%%source_rvalues as %%sku => %%r_value){ %%source_values["%%sku"] = %%source_labels["%%sku"]; } //hide options in target question, unless they are in ticked in the source question foreach(%%tgt_opts as %%label){ //if option value was not selected in source question, hide it from target q if(!(sgapiIn_Array(%%label,%%source_values))){ sgapiRemoveOption(%%target_id, %%label); } } if(sgapiCount(%%source_values) == 0){ sgapiJumpToPage(%%next_pageid); }
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 Textbox List question.
%%next_pageid - The page to jump to if no options are selected in the Checkbox question (and therefore the page with the textbox list question is skipped.
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!